system
December 1, 2016, 9:17pm
1
Attention
Topic was automatically imported from the old Question2Answer platform.
Asked By
sionco
Old Version
Published before Godot 3 was released.
Hi.
I know how to move a 3D kinematic character in 4 directions
ie:
if(Input.is_action_pressed("ui_down")):
acceleration.z=-1
if(Input.is_action_pressed("ui_left")):
acceleration.x=-1
move(acceleration*delta*SPEED)
But, if I want movement where pressing left rotates the character and pressing up always moves the character forwards relative to the characters z direction (not the world z direction), how would I do it? using the kinematic move function to keep physics.
system
December 1, 2016, 10:28pm
4
Reply From:
eons
You will have to move(rotated_movement_vector)
to move on relative directions.
Here, docs on transforms:
http://docs.godotengine.org/en/stable/tutorials/matrices_and_transforms.html
This Codetuto tutorial about rotation and movement in godot:
http://codetuto.com/2016/01/godot-engine-movement-and-rotation-basics/
Also, look at this recent question+answers regarding how to work with transform matrix with an example using move
:
https://forum.godotengine.org/10322/problem-in-using-transform
Thanks. The other person’s question was useful.
For others, I used:
if(Input.is_action_pressed("ui_up")):
accel.z=-10
if(Input.is_action_pressed("ui_down")):
accel.z=10
if(Input.is_action_pressed("ui_right")):
r += Vector3(0,-1,0) * RSpeed * delta
elif(Input.is_action_pressed("ui_left")):
r += Vector3(0,1,0) * RSpeed * delta
move(get_global_transform().basis.xform(Vector3(0,0,accel.z))*delta)
sionco | 2016-12-01 22:52
Be careful with normal (euler) rotations in 3D, sometimes you may need make rotations with Quat