Ok so I'm going nuts over this, The source I'm reading from is here:
http://www.red3d.com/cwr/steer/gdc99/
If you can be bothered reading that, the main concern is with the arrival behaviour. I have setup my object exactly the same as the page says
Simple Vehicle Model:
mass scalar
position vector
velocity vector
max_force scalar
max_speed scalar
orientation N basis vectors
*I have left out orientation and added in force which is used as steeringCode:private var p:Vector; //position private var v:Vector; //velocity private var f:Vector; //force private var mass:Number; private var maxForce:Number; private var maxSpeed:Number;
now when converting this arrival code into flash:
target_offset = target - position
distance = length (target_offset)
ramped_speed = max_speed * (distance / slowing_distance)
clipped_speed = minimum (ramped_speed, max_speed)
desired_velocity = (clipped_speed / distance) * target_offset
steering = desired_velocity - velocity
and then I update the object exactly like the paper describes:Code:var d:Vector = target.subNew(p); //target offset var dist:Number = d.length; var speed:Number = maxSpeed * (dist / 100); speed = Math.min(speed, maxSpeed); var dvx = (speed / dist) * d.x; var dvy = (speed / dist) * d.y; f.x = dvx - v.x; f.y = dvy - v.y;
steering_force = truncate (steering_direction, max_force)
acceleration = steering_force / mass
velocity = truncate (velocity + acceleration, max_speed)
position = position + velocity
the clamp functions looks like:Code:clamp(f, maxForce); var ax = f.x / mass; var ay = f.y / mass; v.x += ax; v.y += ay; clamp(v, maxSpeed); p.x += v.x; p.y += v.y;
But the object continues past the target, as if it were elasticCode:function clamp(n, max){ var len = n.length; if(len > max){ n.x /= len n.y /= len n.x *= max n.y *= max } }
can somebody point out what I have done wrong here, I have found several papers on this all which are exactly the same, use the same formulas, but I can't seem to re-create it in flash.




Reply With Quote