![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | KramchayDig |
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 _physics_process 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
else:
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
else:
velocity.z = lerp(velocity.z,0,.75)
velocity = move_and_slide(velocity, UP)
pass
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.
I don’t want want the player to slide and fly off from the edge like that. Since I used move_and_slide 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.