Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Shlopynoobnoob |
I am moving my 3d character with the arrow keys and when I press the left/right keys the character rotates, but when I press the forward key it moves to the old forward not the new one after the rotation, how can I fix that?
this is the script:
extends KinematicBody
export var speed = 10.0
export var friction = 0.05
export var acceleration = 0.1
var velocity = Vector3()
func _physics_process(_delta):
var wishdir = Vector3()
if Input.is_key_pressed(KEY_LEFT):
wishdir += Vector3.LEFT
get_node("mesh").rotate_y(deg2rad(0.2))
if Input.is_key_pressed(KEY_RIGHT):
wishdir += Vector3.RIGHT
get_node("mesh").rotate_y(deg2rad(-0.2))
if Input.is_key_pressed(KEY_UP):
wishdir += Vector3.FORWARD
if Input.is_key_pressed(KEY_DOWN):
wishdir += Vector3.BACK
wishdir = wishdir.normalized() * speed
if wishdir.length() > 0:
velocity = velocity.linear_interpolate(wishdir, acceleration)
else:
velocity = velocity.linear_interpolate(wishdir, friction)
velocity = move_and_slide(velocity)
Sorry my answer wasn’t working, so I removed it.
Adam_S | 2020-10-07 16:52