0 votes

I have a KinematicBody with a capsule CollisionShape. I move it with the arrows and give it gravity. When it collides against a slope (ramp), it jumps, despite me casting the gravity in the direction of the collision normal. Any ideas?

extends KinematicBody

var speed = 600
var gravity = -9.8
var dir = Vector3()
var vel = Vector3()
var count = {"coll_ramp":0}
var norm = Vector3(1, 1, 1)

func _ready():
    pass

func _physics_process(delta):
    dir = Vector3(0, 0, 0)
    if Input.is_action_pressed("ui_left"):
        dir.x -= 1
    if Input.is_action_pressed("ui_right"):
        dir.x += 1
    if Input.is_action_pressed("ui_up"):
        dir.z -= 1
    if Input.is_action_pressed("ui_down"):
        dir.z += 1
    dir = dir.normalized()
    dir = dir * speed * delta
    if vel.y > 0:
        gravity = -20
    else:
        gravity = -30
    vel.y += gravity * delta
    vel.y *= norm.y
    vel.x = dir.x
    vel.z = dir.z
    vel = move_and_slide(vel, Vector3(0, 1, 0))
    norm = Vector3(1, 1, 1)
    if is_on_floor() and Input.is_action_just_pressed("jump"):
        vel.y = 10
    if get_slide_count() > 0:
        var coll = get_slide_collision(0)
        norm = coll.normal
        if coll.collider is RigidBody:
            coll.collider.apply_impulse(coll.position, -coll.normal * 0.25)
in Engine by (840 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 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 webmaster@godotengine.org with your username.