How to prevent a projectile's rotation ?

Cheo

Active member
Hello, what would be the most appropriate way to have a projectile always stay upright with a rotation value of 0, 0, 0 while it is thrown ? I thought setting the Rotation Speed to zero would be enough, but it isn't. When experimenting and trying to comment out various bits of codes, I noticed that by default the demo grenades are perfectly upright for one frame when spawned, then get titled. In addition when we comment out the following line in Trajectory Object.OnEnable() :

C#:
 m_SimulationIndex = SimulationManager.RegisterSmoothedObject(this);

The grenade is spanwed in an upright position and doesn't move nor rotate. However when uncommenting it and commenting out the content of Rotate and the two Move voids, it is spawned once again upright for one frame only and then stays static and tilted. I wasn't able to pinpoint the moment when the rotation is applied, but at this point I'm suspecting there's something I'm missing at the SimulationManager level.

I hope this question makes sense and hope you can enlighten me on this, thanks.
 
The projectile needs to be registered with the simulation manager otherwise it won't function properly. The projectile rotation is set when it is spawned within SpawnProjectile.SpawnThrowableObject:

Code:
            var previewData = ThrowableAction.GetThrowPreviewData();
            var location = previewData.ThrowTransform;
            m_InstantiatedThrownObject = ObjectPoolBase.Instantiate(m_ThrownObject, location.position, location.rotation, m_ObjectTransform.parent);

So the rotation is based on the throw transform. Does this answer your question?
 
Thanks, it is indeed simply using this throw transform, but to get the projectile standing upright with a rotation of 0, 0, 0 I had to change its euler angles in ProjectileThrower.ThrowInternal, just after the spawnedThrownObject is unparented - that way we are changing the rotation of the projectile once it is in the air and without a parent, which is more appropriate and convenient.

One of my clients needed that for a specific use case in his own project, and off the top of my head I can't remember a commercial game that does this for some spawned throwables so maybe it's a bit of a niche need, but allow me nonetheless to make the suggestion to have a bool and perhaps a Vector 3 in ProjectileThrower to optionally set/offset a detached projectile's rotation.
 
Instead of modifying the ProjectileThrower I recommend creating a new module for this use case - this will make updating easier and is a perfect use case for the modular item system.
 
Back
Top