- Home /
Thrown objects always have same rotation
I am trying to have the player throw a fireball prefab every time the left-mouse button is clicked. The fireball spawns and is thrown away from the player, however, it always goes the same direction. The rotation I give the fireball is that of the camera's X and the player's Y. I can't seem to figure out why it is not using the correct rotation.
if(Input.GetButtonDown("Fire1")){
GameObject temp = (GameObject)GameObject.Instantiate(fireBall,
new Vector3(player.transform.position.x,
player.transform.position.y,
player.transform.position.z),
Quaternion.Euler(camera.transform.eulerAngles.x,
player.transform.eulerAngles.y,
0));
Debug.Log(camera.transform.rotation.eulerAngles.x);
Debug.Log(player.transform.rotation.eulerAngles.y);
temp.rigidbody.AddForce(force, force, force);
Answer by robertbu · Jul 25, 2014 at 05:46 AM
You don't give us enough enough information/code to nail everything down, but assuming your fireball is facing the correct direction (i.e. your Quaternion.Euler() is giving you what you want), the last line is wrong. Here is an alternate:
temp.rigidbody.AddForce(temp.transform.forward * force);
Answer by akashsunny · Jul 25, 2014 at 08:40 AM
the cause is That you are using the camera's euler angles .. By closely observing your game you can find out that the camera's angles are constant that is the problem which is causing the issue. try using the player's angles
if you found this helpful or if there is anything more that you would like to know pls post again.