Hello! I’m trying to do a shooter where the weapon rotates “alone” to the enemy position, for that:
I created 1 player and 1 enemy, the white squares
Inside the Player, I created the weapon as another black square and made it a rectangle (Sprite). To be able to rotate it in a side, I also made it as a child of an emty object (Weapon Pivot).
The issue is, when I press play the sprite becomes almost invisible except for a line. I believe the script (equipped inside Weapon Pivot) works fine because when I press play, the line rotates in direction of the other white square (the enemy) BUT why is it showing like this?
Are your sprites on the same Z value? It looks like the weapon thingy is rotating in 3D
To see if your code works fine, rotate the weapon by hand in the inspector and compare the rotation with the scripts results. IIRC only the y rotation needs to change for this.
Also make sure the pivot of the weapon is at the base so it rotates “physically accurately”
Venediklee tyvm for the reply! You are right, the Z axis was failing.
I changed the script for the function RotateTowards: Unity - Scripting API: Vector3.RotateTowards
The result is the same. I have no clue how to modify only the Z axis letting the X/Y axis alone. If you or any kind soul could help with an explanation or link would be awsome!