I'm working on a two player 3D game that involves both player character models facing toward one another most of the time.
I worked out that i can use translate_object_local(Vector3.MODEL_<side>)
for movement around a point that a model faces toward (there's probably a better way to do that, but that's not what i'm focused on for now), but i'm struggling to make that focus point an object instead of just coordinates.
I've tried a few things inside func _physics_process(delta):
look_at($Beacon.position.x, Vector3.UP, $Beacon.position.z)
to rotate around the Y axis and face the object Beacon (CharacterBody3D placeholder for player 2) crashes with the error "Invalid access to property or key 'position' on a base object of type 'null instance'."
Putting var look_here = position
in the script for the beacon and then look_at($"../Beacon".look_here)
in TestChar (test character) makes the character rotate around the world origin.
Adding a Vector3 variable look_here_P1
to Beacon's script and then adding or subtracting to its X and Y positions with beacon's movement keys should make TestChar face a point that's in the same place as Beacon, but i don't know how to either make TestChar use that that variable from Beacon's script, or move the variable to TestChar and make Beacon update it now that it's in another script.
Making Beacon emit a signal every time it moves in a particular direction and then using those signals to update a Vector3 variable in TestChar's script doesn't seem to work, i think either it doesn't update the variable's position or look_at()
in _physics_process
doesn't check for a new target to look at.
Is there a simple way to make an object always look at another object? I'm sure there must be but i can't seem to figure it out. Thanks in advance.