- Home /
bullet instance firing at 90 degree angle
im creating a projectile instance and setting it's rotation and movement to head toward the mouse but it keeps firing at a 90 degree angle clockwise. Tired toying around but no success, any ideas?
//Get mouse co-ordinates relative to screen
Vector3 mousePosition = Input.mousePosition;
mousePosition = mousePosition;
//Get mouse co-ordinates relative to world
mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
// If the player is facing right...
if(playerCtrl.facingRight)
{
// ... instantiate the rocket facing right and set it's velocity to the right.
Rigidbody2D bulletInstance = Instantiate(rocket, transform.position, Quaternion.LookRotation(transform.position - mousePosition , Vector3.forward)) as Rigidbody2D;
bulletInstance.AddForce(bulletInstance.transform.right * speed);
}
What happens if you do
bulletInstance.AddForce(bulletInstance.transform.forward * speed);
Ins$$anonymous$$d? Because using transform.right is basically saying (1,0,0) * speed, so it will always fly to the right I believe.
fires at 180 degree angle and the projectile is oriented wrong by using bulletInstance.AddForce(bulletInstance.transform.right * speed);
i keep moving right in the projectiles local axis
Answer by trololo · Mar 27, 2014 at 05:02 PM
Don't use AddForce(), but Translate() or MoveToward() to move your bullet from your player location to your target (in Update() or a coroutine).
initially I was just adding a velocity to my rigid body but it would only use the global axis as opposed to it's local axis.