I have a plane entity that has been rotated 90 degrees on the initial start of the game. I am adding a laser function whenever the player presses the space bar. I have set the position of the laser to be next to the player and have the same rotation as the player. The problem is I am unable to detect which way the player is facing and then set the laser to be at the top of the player.
For example, if the player is facing downward, the laser should spawn below the player in order to look like the laser is shooting from the head of the player.
The laser script can be found here.
My project can be found here.
A bit of Vec3 math is what you need.
So you need a vector (0,0,-1) and you want to get rotation of player, and rotate your vector by that rotation. That way your vector now will be pointing into direction of where you player is facing.
Then you want to scale that vector by distance of which you want laser to be far from origin of player.
Then you create laser, position it by position of player + vector you’ve calculated before.
You can use the ‘forward’ property of the player entity to get a vector which points towards the direction that the player is facing.
Awesome, that definitely worked. Thank you Max & Vaios! Really appreciate the quickness and helpfulness.