Author Topic: Adding velocity to a vehicle in the direction it's facing  (Read 1289 times)

I'm making a simple boost for vehicles. How can I add 25 velocity to a vehicle in its forward direction?

Use vectorAdd(%vec1, %vec2) and vectorScale(%vec, %scale) with %vehicle.getVelocity(), %vehicle.getForwardVector(), and %vehicle.setVelocity(%vec).

is there any disadvantage to just using addVelocity rather than setVelocity(vectorAdd(getVelocity, ...))

i would think the former would be much more efficient character-wise and performance-wise but maybe i'm wrong?

anyway the idea is to use getForwardVector, and then scale that to w/e speed you want the boost to be at (eg 25) to get the velocity added, and then add that velocity
« Last Edit: July 05, 2015, 01:40:43 PM by otto-san »

is there any disadvantage to just using addVelocity rather than setVelocity(vectorAdd(...getVelocity, ...))

i would think the former would be much more efficient character-wise and performance-wise but maybe i'm wrong?
Character-wise yes but any difference in performance would be negligibly in favor of setvelocity. Addvelocity is a shortcut intended for use with the events system and is implemented in torque.

Use vectorAdd(%vec1, %vec2) and vectorScale(%vec, %scale) with %vehicle.getVelocity(), %vehicle.getForwardVector(), and %vehicle.setVelocity(%vec).

Thanks. Is this correct?  %vehicle.setVelocity(vectorAdd(%vehicle.getVelocity(),vectorScale(%vehicle.getForwardVector(),25)));
« Last Edit: July 05, 2015, 02:43:05 PM by Farad »

Thanks. Is this correct?  %vehicle.setVelocity(vectorAdd(%vehicle.getVelocity(),vectorScale(%vehicle.getForwardVector,25)));
Yes, it is.