Object doesn't instantiated right spot
I have weird glitch in my game. When player shoot the gun, bullet is instantiated something called "ShootPoint" transform.
This is the ShootPoint's position:
And this is the code of firing bullet:
RigidbodyProjectile CreateBullet() {
GameObject bullet = Instantiate(bulletPrefab, shootPoint.position, shootPoint.rotation);
RigidbodyProjectile projectile = bullet.GetComponent<RigidbodyProjectile>();
projectile.rigidbody.AddForce(shootPoint.forward.normalized * bulletSpeed, ForceMode.VelocityChange);
return projectile;
}
Simple script to just instantiate bullet prefab in ShootPoint.transform.
However when I run the game, bullet generated totally wrong place:
That picture captured right after creation, even before push the bullet. Here's the updated code for capture that moment, I intentionally throw the error so that makes game stop:
RigidbodyProjectile CreateBullet() {
GameObject bullet = Instantiate(PrefabManager.GetPrefab("bullet"), shootPoint.position, shootPoint.rotation);
// Throw the exception
throw new System.Exception("DIE");
// So codes under here will not work
RigidbodyProjectile projectile = bullet.GetComponent<RigidbodyProjectile>();
projectile.rigidbody.AddForce(shootPoint.forward.normalized * bulletSpeed, ForceMode.VelocityChange);
return projectile;
}
I don't get it, why my bullet doesn't generated in ShootPoint.transform? I literally removed all components in Bullet and tried again but still had same problem.
Funny thing is that this is not always happening, it only happens in certain angles, especially looking down. I already checked hundreds that ShootPoint pointing something wrong direction or reference of ShootPoint was wrong, but no, there was no problem at all!
What should I check in this case? It's really annoying issue, because when I shoot little lower angle, it always hit the ground almost instantly after fire.
Anyone who knows about this issue, if could be great what should I check, thanks.
Your answer

Follow this Question
Related Questions
How to spawn a prefab at a duplicate objects location 1 Answer
Moving a GameObject that was instantiated,Problem moving an instantiated Object. 0 Answers
Instantiate Causes errors when I spawn multiple particle prefabs at once. 1 Answer
Why more balls are instantiating? 0 Answers
Rotation not working properly when ,Script rotation not working when instansiating. 0 Answers