• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Drift spell

Status
Not open for further replies.
Level 25
Joined
Jul 10, 2006
Messages
3,315
By basing movement on acceleration rather than velocity.

Simplest way is to have two variables for the unit: x velocity and y velocity, let's call them dx and dy (both reals). (google component vectors if you want to understand it better)

The movement trigger, which will fire every 0.03 seconds, simply moves the unit based on dx and dy.

Use custom script: call SetUnitX(udg_unit, GetUnitX(udg_unit) + udg_dx)
and the same for dy, replacing all instances of X with Y in that script.

Next we need a trigger that sets dx and dy.

Since this trigger will be a little more "costly" in terms of calculations required, let's make it every 0.2 seconds or so.

The action will be, once again splitting it into X and Y;
Set dx = dx + (acceleration * cos(facing of unit))
Set dy = dy + (acceleration * sin(facing of unit))

We are adding the acceleration to the existing velocity so that it is gradual; if you want to drift around a corner, as you turn, your car is still going in another direction.
dx and dy can both go negative, to allow for west and south facing movement.

cos & sin are the lengths of sides based on angles in a triangle... do a google search for this as well.

If this all just doesn't make sense to you, I might have a trigger lying around that does this.
 
Level 3
Joined
Sep 30, 2011
Messages
60
By basing movement on acceleration rather than velocity.

Simplest way is to have two variables for the unit: x velocity and y velocity, let's call them dx and dy (both reals). (google component vectors if you want to understand it better)

The movement trigger, which will fire every 0.03 seconds, simply moves the unit based on dx and dy.

Use custom script: call SetUnitX(udg_unit, GetUnitX(udg_unit) + udg_dx)
and the same for dy, replacing all instances of X with Y in that script.

Next we need a trigger that sets dx and dy.

Since this trigger will be a little more "costly" in terms of calculations required, let's make it every 0.2 seconds or so.

The action will be, once again splitting it into X and Y;
Set dx = dx + (acceleration * cos(facing of unit))
Set dy = dy + (acceleration * sin(facing of unit))

We are adding the acceleration to the existing velocity so that it is gradual; if you want to drift around a corner, as you turn, your car is still going in another direction.
dx and dy can both go negative, to allow for west and south facing movement.

cos & sin are the lengths of sides based on angles in a triangle... do a google search for this as well.

If this all just doesn't make sense to you, I might have a trigger lying around that does this.
could you attach the map? :ogre_love:
 
Level 4
Joined
Aug 26, 2012
Messages
123
Umm, how if we want to use a polar offset?
Ruleonfire's answer is good, but I'd rather use polar offset than cartesian... Any idea?
(I'm sorry, Cartesius. I'd rather use center-position-based than X-Y-based...)
 
Level 4
Joined
Aug 26, 2012
Messages
123
Oh... Thanks, rulerofiron, I just think polar offset will also works...

(Heh, you just say his nickname above this, as "ruleonfire". How inconsistent)
 
Status
Not open for further replies.
Top