0 votes

I used Godot 3.1

I don't understand why the 3D kinematic controls have different sliding system to the 2D kinematic controls when I try to code similarly to the 2D controls I had. The problem isn't visible if I don't use any collision shapes that has curved bottom or top like cylinder, box. If I use a capsule or maybe a sphere I would fly off when I walk to an edge or let's say a stair or something and this problem only happens in the 3D world but not in 2D I checked up on it. I'll show the code I wrote in the physicsprocess the basic movements for the player in 3D.

extends KinematicBody

var velocity = Vector3(0,0,0)
export var SPEED : float = 8
const UP = Vector3(0,1,0)

func _physics_process(delta):

var g = Vector3(0,-9.8,0)

velocity += g * delta

if Input.is_action_pressed("right") and Input.is_action_pressed("left"):
    velocity.x = 0
elif Input.is_action_pressed("right"):
    velocity.x = SPEED
elif Input.is_action_pressed("left"):
    velocity.x = -SPEED
    velocity.x = lerp(velocity.x,0,.75)

if Input.is_action_pressed("forward") and Input.is_action_pressed("backward"):
    velocity.z = 0
elif Input.is_action_pressed("backward"):
    velocity.z = SPEED
elif Input.is_action_pressed("forward"):

    velocity.z = -SPEED
    velocity.z = lerp(velocity.z,0,.75)

velocity = move_and_slide(velocity, UP)


Here is a gif where I walk to an edge and player flies I didn't jump I didn't include a jump control on it.
enter image description here

I don't want want the player to slide and fly off from the edge like that. Since I used moveandslide only to the 3D, the code must have applied something to slide and fly when walking to an edge. I'm not sure about it yet but I want to know what's going on.

asked Jul 3, 2019 in Engine by KramchayDig (48 points)

2 Answers

+1 vote
Best answer

It behaves quite realistically, exactly what I would expect in real life.
Here's a few things you can try:

  • Add a PhysicsMaterial and increase the friction (and experiment with the other properties).
  • Use move_and_collide instead of move_and_slide (it has "slide" in the name, you should expect it to slide)
  • Increase the gravity
answered Jul 3, 2019 by Dlean Jeans (3,864 points)
selected Jul 4, 2019 by KramchayDig
0 votes

move_and_slide got a parameter called stop_on_slope if you set it to true, it will still slide but not fly:

velocity = move_and_slide(velocity, UP, true)
answered Jul 4, 2019 by Dlean Jeans (3,864 points)
edited Jul 4, 2019 by Dlean Jeans

I already did that but if you walk to the tip of an edge you would fly off.

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.