在KinematicBody上挂的脚本,使用move_and_slide()进行移动
根据运动学车身:停在斜坡上(建议挂梯子,不挂也行,但可能要刷新几次才能进)
把move_and_slide()下的stop_on_slope改成了true
move_and_slide(motion, Vector3.UP, true)
但是还是站不住30°的斜坡
斜面和三角形我都试过了(与斜面坡度差不多,没过45°)
都不行
求助
extends KinematicBody
var sensitivity = 0.075
var resistance = 0
var motion = Vector3()
var gravity = Vector3()
var acceleration = Vector3()
var location = Vector3()
var jump_detect = true
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _input(event):
if event is InputEventMouseMotion:
$头.rotate_object_local(Vector3.RIGHT, deg2rad(-event.relative.y * sensitivity))
rotate_object_local(Vector3.UP, deg2rad(-event.relative.x * sensitivity))
$头.rotation.x = clamp($头.rotation.x,deg2rad(-90),deg2rad(90))
func _process(delta):
location = Vector3()
gravity += -self.transform.basis.y * delta * 30
if is_on_floor():
resistance = 9
jump_detect = true
location
else:
resistance = 2
jump_detect = false
print(jump_detect)
if Input.is_action_just_pressed("Space") and jump_detect:
gravity = self.transform.basis.y * 10
jump_detect = false
if Input.is_action_pressed("W"):
location -= transform.basis.z
elif Input.is_action_pressed("S"):
location += transform.basis.z
if Input.is_action_pressed("A"):
location -= transform.basis.x
elif Input.is_action_pressed("D"):
location += transform.basis.x
motion = motion.normalized()
acceleration = acceleration.linear_interpolate(location * 6 ,resistance * delta)
motion.z = acceleration.z + gravity.z
motion.x = acceleration.x + gravity.x
motion.y = gravity.y
move_and_slide(motion, Vector3.UP, true)