Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | nate066 |
I have my 3rd person character controller almost working but it has a couple glitches which im not sure how to solve. The glitches are
-
When moving and pressing jump the character jolts forward
-
when camera is rotated up looking down at the character the character wont move or moves slowly.
-
the movement is not smooth, its jittery/jumpy, im guessing interpolation would fix this one. This is fixed, was not part of the character controller, the issue was that godot was lagging while updating the remote scene this can be turned of by clicking local while playing the game in the editor inspector.
here is a video of the issues: https://streamable.com/ogf8r
extends KinematicBody
export var speed = 50
export var up = Vector3(0, 1, 0)
export var gravity = 0.98 #Gravity Feels off, its linear it doesnt speed up gradually : FIXED
export var jump_force = 25
export var jump_count = 2
export var health = 100
export (float) var mouseSensitivity = 0.1
var yaw = 0.0
var pitch = 0.0
var dist = 4.0
var dir = Vector3(0,0,0)
var vdir = Vector3(0,0,0)
var jump_cnt = 0
func _ready():
#Setup Clipped Camera
$Rotation/ClippedCamera.process_mode = ClippedCamera.CLIP_PROCESS_PHYSICS
$Rotation/ClippedCamera.add_exception(self)
#Set Mouse mode to captured, so, it doesnt show.
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
#Mouse And Rotation
func _input(event):
if event is InputEventMouseMotion:
var mouseVec : Vector2 = event.get_relative()
yaw = fmod(yaw - mouseVec.x * mouseSensitivity , 360.0)
pitch = max(min(pitch - mouseVec.y * mouseSensitivity , 90.0), -90.0)
$Rotation.set_rotation(Vector3(deg2rad(pitch), deg2rad(yaw), 0.0))
func _physics_process(delta):
#Gravity
if not is_on_floor():
vdir.y -= gravity
#Left Right movment
if Input.is_action_pressed("ui_right"):
dir.x = 1
elif Input.is_action_pressed("ui_left"):
dir.x = -1
else:
dir.x = 0
#Forward Back Movement
if Input.is_action_pressed("ui_up"):
dir.z = -1
elif Input.is_action_pressed("ui_down"):
dir.z = 1
else:
dir.z = 0
#Jumping
if Input.is_action_just_pressed("ui_accept"):
if jump_cnt < jump_count:
vdir.y = jump_force
jump_cnt += 1
#apply basis
var basis = $Rotation.transform.basis
basis.y = transform.basis.y
dir = dir.normalized()
dir = basis * dir
print(basis)
dir = dir * speed
dir.y = vdir.y
#Apply Movement
var mov = move_and_slide(dir, up)
if is_on_floor(): #is_on_floor() Should be after move_and_slide()
jump_cnt = 0
Thanks for the help!