- Home /
Question by
Desmazio · May 24, 2020 at 08:50 AM ·
unity 2dtrigonometry
Can't get the right position of the player
Hello, I made a laser beam that should hit the player, but it goes a little under the player:
This is the code:
private Vector3 GetPlayerPosition()
{
Vector3 pos = GameObject.Find("Player").transform.position;
return pos;
}
private float GetPlayerAngulation()
{
Vector3 player_pos = GetPlayerPosition();
Vector3 direction = player_pos - transform.position;
rotation_z = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
return rotation_z;
}
IEnumerator FireLaser()
{
while(true)
{
if (!is_first_attack)
shark_eye.GetComponent<SharkEye>().Fire(rotation_z);
else
is_first_attack = false;
yield return new WaitForSeconds(laser_reload);
}
}
This part: shark_eye.GetComponent().Fire(rotation_z); only instantiate the laser in the shark's eye. Thank you.
cattura.png
(506.4 kB)
Comment
Best Answer
Answer by Desmazio · May 26, 2020 at 01:14 PM
Nvm I resolved this a few days ago. Simply at line 10 I had to change "transform.position" with the position of the eye.
Your answer
Follow this Question
Related Questions
Lerping between two colors to create day/night effect in unity2D 1 Answer
Best way to implement character(2d) interaction with other objects or characters 0 Answers
How to access two WheelJoint2D from C#? 0 Answers
Unity Build failed with errors, 0 Answers
Unity UI Buttons don't work with Input.GetAxisRaw("Horizontal") 0 Answers