system
September 7, 2016, 2:36am
1
system
September 7, 2016, 12:53pm
4
Reply From:
Zylann
You can get the world-space forward direction of a Camera node by getting its Z axis:
# Don't forget the minus sign. It's because Godot follows OpenGL's convention
var forward_vector = -camera_node.get_global_transform().basis.z
Then you can use this vector to move your character’s root node.
Note: you can also get the X axis if you want to strafe.
Reply From:
LettucePie
Post is Super Old, however I was facing similar issue and had this tab opened mocking me with it’s inefficiency. I have since solved my issue and figured I should share. You were most likely looking for: transform.xform(variant)
. Here is the link to the documentation https://docs.godotengine.org/en/stable/classes/class_transform.html#class-transform-method-xform
Here is how I utilized it:
Scene Tree
Spatial (Spatial.gd)
/Player
//CamPivot
///Camera
Script (Spatial.gd)
func _input(event):
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT:
pressed = event.pressed
if event is InputEventMouseMotion and pressed:
var pos = $Player.transform.origin
var inputDirection = Vector3(
event.relative.x,
0,
event.relative.y)
inputDirection = $Player/CamPivot.transform.xform(inputDirection)
pos.x += (inputDirection.x * 0.05)
pos.z += (inputDirection.z * 0.05)
$Player.transform.origin = pos