I have an enemy that will go towards the player and once in attack range, throw a grenade every 2 seconds.
The object is instantiated at the enemy’s position and rotation, and the force is applied in the enemy’s forward direction. The enemy also looks at the player right before this. However, the enemy’s grenade goes sideways. I have changed the addforce to enemything.transform.right, but then the grenade actually goes right, and I have verified that the enemy is facing towards the player. The grenade prefab also has 0, 0, 0 rotation values.
The forward vectors is the correct approach. Your prefab may be rotated, or the children of the prefab root may be rotated. Edit the prefab in isolation, and toggle the “local space, world space” mode; the blue arrow should face the same way in either mode, and the models aligned properly for that forward direction.
So I have figured out that the enemy and grenade prefab are both faced in the correct direction. When I removed the line of rigidbody addforce, the grenade dropped directly under the enemy. So the issue is in the line of code
“clone.GetComponent().AddForce(enemything.transform.forward * 800);”
but I have paused the scene as the enemy dropped the grenade, and it goes directly right. I then changed the “transform.forward” to “-transform.right” but this just makes the enemy throw them diagonally behind it. The enemy’s blue z axis arrow still always points towards the player, but the grenade’s points toward the enemy. This made me try changing the “transform.forward” to “-transform.forward” but this makes the enemy throw them diagonally behind it again. I have figured out that standing directly in front of the enemy makes the grenade drop down with little force, and when I go to the left, the grenade is thrown to the enemy’s right, and when I go to the right, the grenade is dropped to the enemy’s left. So the grenade is thrown in a line parallel to the player which confuses me, because the grenade prefab rotation is normal, and the enemy’s rotation is normal, but the instantiated prefab’s is not. I can’t fix the issue, but I know it is an Issue with the rigidbody addforce line, and in the instantiated prefab. The grenade script also has no references to rotation or transform at all, just exploding and etc.