Page MenuHomeFeedback Tracker

setVelocity onEachFrame destroys grenade physics
New, WishlistPublic

Description

Using setVelocity within an onEachFrame makes grenade fly in an almost straight line.

Details

Legacy ID
2629181600
Severity
None
Resolution
Open
Reproducibility
Always
Category
Scripting
Steps To Reproduce

Run this:

onEachFrame "currentProjectile setVelocity (velocity currentProjectile)";
player addEventHandler ["fired", {currentProjectile = _this select 6;}];

And throw a grenade.

Additional Information

This makes it impossible to use onEachFrame to modify physics. Of course if physics were perfect we wouldn't need it, but they aren't (ex: wind effects are missing).

Event Timeline

galzohar edited Steps To Reproduce. (Show Details)Nov 30 2013, 1:44 AM
galzohar edited Additional Information. (Show Details)
galzohar set Category to Scripting.
galzohar set Reproducibility to Always.
galzohar set Severity to None.
galzohar set Resolution to Open.
galzohar set Legacy ID to 2629181600.May 7 2016, 5:32 PM

As far my logic goes, you're doing it wrong.

You're accelerating the object forward on each frame by the same amount of energy. No wonder the grenade's doing a straight line.

If you want to describe a parabola manually, you need to reduce the forward energy according to your own loss of kinetic energy calculations, all the way down to 0, while the object should drop according gravity on its own eventually, as gravity physics should still apply then.

In this example no acceleration is applied. Velocity is speed in meters per second (aka [Vx, Vy, Vz]). Setting V to the same value as the current value of V should have no effect.

For anything other than grenades, setting V to the same value it already has indeed has no effect. Only grenades get their simulation disabled on frames where setVelocity is used, hence it is a bug. Simulation should not be completely (or mostly) ignored on frames where setVelocity is used, especially not when this only happens with grenades.

Repeat the test with any other projectile and notice only grenades are affected by this bug.