Godot Engine

Godot Engine

なかの31 Jan 17, 2024 @ 6:08pm
Rotating an object based on a vector3 value.
I made use of that a long time before, but was only in 2D, and I'm struggling to find out how to do this on 3D.

I created a projectile object which has a velocity variable, which will be used to move the projectile per physics frame in a direction. The problem, is that the projectile (an arrow) is intended to be rotated, with its tip facing the direction it is flying, and I have no clue how to do that.

Anyone could give me an idea of how I could get which direction the arrow should be rotated based on its velocity? I tried googling about this issue, but I got a lot of irrelevant infos, probably because I searched for the incorrect thing.
Originally posted by umop-apisdn:
Every 3D object inherits from Spatial, which has a look_at() method.
Just make sure your arrow model is "facing" negative Z.

https://docs.godotengine.org/en/3.1/classes/class_spatial.html#class-spatial-method-look-at
< >
Showing 1-7 of 7 comments
The author of this thread has indicated that this post answers the original topic.
umop-apisdn Jan 17, 2024 @ 8:38pm 
Every 3D object inherits from Spatial, which has a look_at() method.
Just make sure your arrow model is "facing" negative Z.

https://docs.godotengine.org/en/3.1/classes/class_spatial.html#class-spatial-method-look-at
Last edited by umop-apisdn; Jan 17, 2024 @ 8:41pm
なかの31 Jan 17, 2024 @ 8:41pm 
Crap...
I might have been quite dumb here...
If I use look_at(), and set the value as the position of the object plus velocity....
That will do...?
umop-apisdn Jan 17, 2024 @ 8:43pm 
Originally posted by なかの29:
Crap...
I might have been quite dumb here...
If I use look_at(), and set the value as the position of the object plus velocity....
That will do...?
That sounds reasonable, yes.
なかの31 Jan 17, 2024 @ 8:51pm 
...Yeah, that seems to work.
Thanks. Now I'll go try making the arrow fly on its tip, instead of the side.
umop-apisdn Jan 17, 2024 @ 8:57pm 
Originally posted by なかの29:
Now I'll go try making the arrow fly on its tip, instead of the side.

Originally posted by umop-apisdn:
Just make sure your arrow model is "facing" negative Z.
なかの31 Jan 17, 2024 @ 9:16pm 
I actually had to rotate the arrow model and collision -90 in X angle...
Seems like 3D models are not like 2D models, where models should be facing upwards.

At least now the arrow is flying correctly. Yay!
Orange Guise Jan 19, 2024 @ 10:50pm 
Watch out for Gimbal Lock.
< >
Showing 1-7 of 7 comments
Per page: 1530 50

Date Posted: Jan 17, 2024 @ 6:08pm
Posts: 7