Using setVelocity within an onEachFrame makes grenade fly in an almost straight line.
Description
Details
- Legacy ID
- 2629181600
- Severity
- None
- Resolution
- Open
- Reproducibility
- Always
- Category
- Scripting
Run this:
onEachFrame "currentProjectile setVelocity (velocity currentProjectile)";
player addEventHandler ["fired", {currentProjectile = _this select 6;}];
And throw a grenade.
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
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.