+1 vote

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

  1. When moving and pressing jump the character jolts forward

  2. when camera is rotated up looking down at the character the character wont move or moves slowly.

  3. 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

    #Set Mouse mode to captured, so, it doesnt show.

#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):

    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

        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

        dir.z = 0       

    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

    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!

in Engine by (23 points)
edited by

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.