heres some code from the script
extends KinematicBody
# NodePaths
export(NodePath) var camera_path
export(NodePath) var weapon_camera_path
export(NodePath) var weapon_manager_path
export(NodePath) var weaponsway_path
export(NodePath) var footstep_path
# References
onready var camera = get_node(camera_path)
onready var weapon_camera = get_node(weapon_camera_path)
onready var weapon_manager = get_node(weapon_manager_path)
onready var weaponsway = get_node(weaponsway_path)
onready var footsteps = get_node(footstep_path)
# Input Parameter
const MOUSE_SENSITIVITY = 0.1
# Movement
var velocity = Vector3.ZERO
var velocity_info = Vector3.ZERO
var current_vel = Vector3.ZERO
var dir = Vector3.ZERO
var snap = Vector3.ZERO
export var SPEED = 10
export var SPRINT_SPEED = 20
const ACCEL = 15.0
# Jump
export var GRAVITY = -40.0
const JUMP_SPEED = 15
var jump_counter = 0
const AIR_ACCEL = 9.0
#foview
export var weaponFOV = 40
export var weaponRunFOV = 50
#headbob
export var headBobFrequency = 1.5
var nextFootStep = 0
var stepInterval = 0.5
var prevGrounded = false
export var headBobHeight = .35
const headBobSwayAngle = 0.5
export var headBobSideMovement = 0.75
export var bobHeightSpeedMultiplier = 0.35
export var bobStrideSpeedLengthen = 0.35
export var jumpLandMove = 0.2
export var jumpLandTilt = 20
export var idleMove = 0.01
export var springElastic = 1.25
export var springDampen = 0.77
export var clampSpring = 0.5
var time = 0.0
var prevVelocity = Vector3.ZERO
var prevPosition = Vector3.ZERO
var springPos = 0
var springVelocity = 0
var headBobFade = 0
var headBobCycle = 0
var xPos = 0
var yPos = 0
var xTilt = 0
var yTilt = 0
#weaponsway
var cam_basis_last_frame = Basis()
var player_basis_last_frame = Basis()
var player_translation_last_framex= 0.0
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _process(delta):
window_activity()
var softness = 2.0
var cam_basis_this_frame = $CamRoot.transform.basis
var player_basis_this_frame = self.transform.basis
var player_translation_this_framex = self.translation.x
var offset1 = calculate_sway_offset(cam_basis_last_frame, cam_basis_this_frame)
var offset2 = calculate_sway_offset(player_basis_last_frame, player_basis_this_frame)
var offset3 = player_translation_last_framex - player_translation_this_framex
var offset = Vector3(offset2.x, offset1.y,-offset3) #may need to swap 1 and 2
do_sway(weaponsway, offset, delta * softness)
cam_basis_last_frame = cam_basis_this_frame;
player_basis_last_frame = player_basis_this_frame;
player_translation_last_framex = player_translation_this_framex
func calculate_sway_offset(basis_last_frame: Basis, basis_current_frame: Basis):
var q1 = basis_last_frame.get_rotation_quat()
var q2 = basis_current_frame.get_rotation_quat()
var q = q1.inverse() * q2
var eu = q.get_euler()
return Vector2(eu.y, eu.x)
func do_sway(sway_node, offset: Vector3, fract: float):
var offset_quaternion: Quat = Quat(Vector3.UP, offset.x) * Quat(Vector3.RIGHT, offset.y)* Quat(Vector3.FORWARD,offset.z)
sway_node.transform.basis = Basis(Quat(sway_node.transform.basis).slerp(offset_quaternion, fract))
func _physics_process(delta):
process_movement_inputs()
process_vertical_movement(delta)
process_movement(delta)
func process_movement_inputs():
# Get the input directions
dir = Vector3.ZERO
if Input.is_action_pressed("forward"):
dir -= global_transform.basis.z
if Input.is_action_pressed("backward"):
dir += global_transform.basis.z
if Input.is_action_pressed("right"):
dir += global_transform.basis.x
if Input.is_action_pressed("left"):
dir -= global_transform.basis.x
# Normalizing the input directions
dir = dir.normalized()
func process_vertical_movement(delta):
# When on floor - Reset vertical movement & completely disable wallrunning
if is_on_floor():
jump_counter = 0
velocity.y = -0.01
# Apply gravity
else:
velocity.y += GRAVITY * delta
#check landing
if !prevGrounded && is_on_floor():
footsteps.playLandSound()
# Jump
if Input.is_action_just_pressed("jump") and jump_counter < 1:
jump_counter += 1
velocity.y = JUMP_SPEED
snap = Vector3.ZERO
footsteps.playJumpSound()
else:
snap = Vector3.DOWN
prevGrounded = is_on_floor()
func process_movement(delta):
# Set speed and target velocity
var speed = 0
if Input.is_action_pressed("sprint") and Input.is_action_pressed("ads") == false:
speed = SPRINT_SPEED
else:
speed = SPEED
var target_vel = dir * speed
# Smooth out the player's movement
var accel = ACCEL if is_on_floor() else AIR_ACCEL
current_vel = current_vel.linear_interpolate(target_vel, accel * delta)
# Finalize velocity and move the player
velocity.x = current_vel.x
velocity.z = current_vel.z
velocity_info = move_and_slide_with_snap(velocity, snap, Vector3.UP, true, 4, deg2rad(45))
# Apply Effects
process_movement_effects(speed, delta)
ApplyBob(delta)
playfootsounds()