[ODE] getting an entity to follow another
Bram Stolk
bram at sara.nl
Mon Sep 4 07:20:34 MST 2006
Dan wrote:
> Hi,
>
> My entities in my game have functions goLeft(), goRight() which apply
> dBodyAddRelTorque to steer them, then I add forward force to move
> them.
>
> I want one entity to follow another, how do I do this? I only need it
> in the horizontal plane.
>
> I guess something can be done with the first entity's angle and the
> target entity's position.
Yep... and if you want to make them smart, you could predict the target
position at t+dt, so that you can 'cut him off'.
>
> But I have no idea how to get the bearing to the target position or to
> get the entities angle from its matrix or quaternion or how to compare
> them if I could...
Well... assuming that:
* you do everything in the xy plane
* traveldir is in x-dir (you apply force in local-x, you apply
steer torque in global or local z)
..then your current aim for interceptor is simply the local x-axis
of the current orientation of the interceptor body.
This means you simply get the matrix, and use row 0, which is local x.
Next, you have a desired aim (based on delta-pos, and optionally
include velocity of target for smarter intercepting).
The angle between these two vectors should be minimized.
(For angle, take acos of dot prod of two unit vectors)
This could be achieved e.g. with an AMotor on the interceptor.
You could e.g. set an angular speed proportional to the aiming
error.
LMotor and AMotor are easier to work with than doing this via forces.
Personally, I find it quite difficult in ODE to force a position
or orientation, because of the enormous indirection:
You want to move a body with dx, then you set a force, which
causes accel, which causes velocity, which causes movement.
You need to consider body mass, overshooting, gravity, and mind
excessive forces if you want to do the movement in too small a
timedelta. LMotor and AMotor have one level of indirection less...
you can specify a desired vel, and you can cap the max force.
Bram
> Any help appreciated!
>
> Thanks,
>
> Dan
> _______________________________________________
> ODE mailing list
> ODE at q12.org
> http://q12.org/mailman/listinfo/ode
--
Bram Stolk, VR Engineer SARA, Amsterdam. tel +31 20 592 3000
"Windows is a 32-bit extension to a 16-bit graphical shell for an 8-bit
operating system originally coded for a 4-bit microprocessor by a 2-bit
company that can't stand 1 bit of competition."
More information about the ODE
mailing list