【发布时间】:2021-06-16 07:30:04
【问题描述】:
我为一个运动角色写了一些代码,只有 W 键(前进)起作用,当我按下 w 和 d 或 a 时,它开始移动但缓慢地向左或向右移动。有人知道如何解决这个问题吗?
extends KinematicBody
var gravity =Vector3.DOWN * 12
var speed = 4
var jump_speed = 6
var spin = 0.1
var velocity = Vector3()
func _physics_process(delta):
velocity += gravity * delta
get_input()
velocity = move_and_slide(velocity,Vector3.UP)
func get_input():
velocity.x = 0
velocity.z = 0
if Input.is_action_pressed("move_UP"):
velocity.z -= speed
if Input.is_action_pressed("move_DOWN"):
velocity.x -= speed
if Input.is_action_pressed("strafe_Right"):
velocity.x -= speed
if Input.is_action_pressed("strafe_Left"):
velocity.z -= speed
func _unhandled_input(event):
if event is InputEventMouseMotion:
rotate_y(-lerp(0, spin, event.relative.x/10))
【问题讨论】:
标签: game-engine godot