The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

I've been trying to use KinematicBody for character movement, but It's behaving pretty unexpectedly. It's compounding the force of gravity but only when in motion. here's the entire script:

extends KinematicBody

var velocity = Vector3.ZERO
var max_acceleration = 100
var max_speed = 10
var max_ground_angle = 45
var movement_input = Vector2.ZERO
var snap_normal = Vector3.DOWN
var snap_distance = 0.2

func _process(delta):
    movement_input = Vector2(
        Input.get_action_strength("move_right") - 
        Input.get_action_strength("move_down") - 

    movement_input.x = clamp(movement_input.x, -1, 1)
    movement_input.y = clamp(movement_input.y, -1, 1)
func _physics_process(delta):

    var gravityNormal = ProjectSettings.get_setting("physics/3d/default_gravity_vector")
    var gravityStep = (gravityNormal * ProjectSettings.get_setting("physics/3d/default_gravity")) * delta
    velocity += gravityStep

    var max_speed_change = max_acceleration * delta
    var desired_velocity = (Vector3(movement_input.x, 0, movement_input.y) * max_speed)

    velocity.x = desired_velocity.x
    velocity.z = desired_velocity.z

    velocity = move_and_slide(velocity, Vector3.UP, true, 4, deg2rad(max_ground_angle))

The ray is casting to the velocity vector while capsule is in motion.

Godot version v3.4
in Engine by (16 points)

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.