Hi! So I have a script where i rotate an enemy to face the player.Then I want the enemy to shoot a projectile at the angle the enemy is.I have tryed alot of different codes from the internet to shoot the projectile forward but instead my projectile does not move at all.
this causes the same thing:
“rigidbody2D.AddForce(Vector3.forward * Speed)”
I also tryed
rigidbody2D.AddForce(transform.forward * Speed)"
In both cases the projectile does not move.
Any help is apreciated.Thank you
Have you tried changing rigidbody2D.AddForce(Vector3.forward Speed) to rigidbody2D.AddRelativeForce(Vector3.forward Speed) I don't know how it works with Vector3.forward. but I've used something similar with an x variable for adjusting (projectileSpeed).
– Stealthygolemsame result
– RedDevilTake a look at my code for a projectile shooting thing: GameObject Clone; Clone = (Instantiate (bulletPrefab, transform.position, transform.rotation)) as GameObject; Clone.rigidbody2D.AddRelativeForce (new Vector2 (-bulletSpeed, 0)); If I change it to only AddForce, it only shoots in the same direction. Teh AddRelativeForce makes it so that the X-value is proportional to the rotation.
– Stealthygolemthe problem is that i want it to go on the Z direction and if i just use forward it does not move at all
– RedDevil