-

it looks like in your diagram, you want the object to point towards the current velocity. Call

obj.lookAt(obj.getPos(render)+currentVelocity)

every frame, maybe?

So it’s not quite clear what you’re asking for. If you’re not looking to rotate the object to face your new vector, maybe you want to move the object in the direction of the vector? But isn’t this just object.setPos(object, vector)? Or, if the vector is in the coordinate space of the parent (as is more common), it would be object.setPos(object.getPos() + vector).

David

I really can’t figure out just what you’re asking here either. Did you ever get the steering behavior implemented? How did you do it?

It seems to me that in the seek behavior you were going for you compute the steering vector as you said:

    desired_velocity = normalize (position - target) * max_speed
    steering = desired_velocity - velocity

You then feed that steering vector into the simple vehicle model (earlier in the same paper you linked to) as the steering force (Correction: steering_direction, not steering_force)) in this code:

    steering_force = truncate (steering_direction, max_force)
    acceleration = steering_force / mass
    velocity = truncate (velocity + acceleration, max_speed)
    position = position + velocity

Which updates the vehicles position in such a way that it steers toward the target. Do both blocks of code once per frame. This code is apparently based on ‘forward Euler integration.’ On the face of it I am not exactly sure what the two calls to truncate mean. Does

truncate (steering_direction, max_force)

mean to clip the magnitude of the vector steering_direction to max_force, or do you clip each component of steering_direction to max_force? Maybe there is a standard meaning of ‘truncate’ in vector math that would explain it.

Edit: Anyway, this code should implement the ‘point mass approximation’ physics that Reynolds describes as simple but not very compelling. For something more realistic you need to use Panda’s physics engine or integrate another physics engine. There is actually a chapter on physics in the Panda3D manual which I was able to use to apply a couple of forces (gravity, and a directional thrust to a character wearing a jetpack) and to turn the forces on and off. I could post sample code for this if you want. I couldn’t figure out how to get collision detection working with the physics though, which makes it a bit silly because if you don’t use the thruster gravity will pull the character right down through the ground.

I think I know what you’re trying to do.
If I get it correctly, that’s something I’ll have to do later for my game (homing missiles).

You want your spaceship to travel a ballistic flight path towards the target.
Which means you don’t want to use a lookAt (it would work, but would look unnatural).

I have an idea for a less sophisticated approach to this problem.
The idea is to get the lookAt angles of your object for the current position (the angles where your object would directly face your target).
Then you write a task that will adjust the current angles of your object in a way that it will turn smoothly to face the target.
For example, your current angle is hpr(0,0,0) and your target would be at h’p’r’(80,80,80) you would write something like this:

*pseudcode*

def fuTask(self, task):
    ****after a delay do: ****
    if h<h' then h = h + 0.1
    if h>h' then h = h - 0.1
...
    update.hpr()

Well, it’d actually be really worthwhile having a Panda3D implementation of the seek behavior that IPKnightly was trying to implement from the Craig Reynolds paper. That would necessarily mean we’d have an implementation of the Simple Vehicle Model on which all the steering behaviors in that paper are based. Once we have seek, we get flee for free. From there, pursuit and evasion, offset pursuit and arrival seem pretty trivial. And obstacle avoidance and path following would not be far off, wandering is pretty easy too… it’s pretty powerful stuff. And OpenSteer is an open source C++ implementation of much of it, we could look at its source code for guidance.

That’s weird, I really thought that the steering behaviors were just vector math, so that the ‘force’ could just be applied to the heading of the vehicle.

Anyway, the Panda API says you should not derive from that class PhysicsObject but should derive from Physical, which provides the methods [add/remove]AngularForce and [add/remove]LinearForce. It apparently lets you add and remove multiple forces to/from an object. Looks promising?

I don’t see at a glance how you step the object and get information from it about position and heading. Maybe it inherits from PhysicsObject? In which case you could use getPosition, getOrientation, getRotation, getVelocity. But it’s late here, I’m tired. Something to look into.

I wouldn’t mind a bit more explanation about why exactly you can’t just apply the ‘force’ to the heading of the object in the way I described. I haven’t read the Reynolds paper too carefully but I really hadn’t noticed that you needed a physics model to be running. The way I read it was that he basically avoided the need for any physics model by assuming a very simple ‘point mass’, which doesn’t give realistic behavior for cars and aircraft, but would be fine for steering simple boids and people. If you wanted to extend it to realistically model the mass of a vehicle under steering, then I could see why you’d need a physics engine…

Okay, clarifications (I edited my earlier post with the code segments to reflect these).

I think the forward Euler integration for which Reynolds gives pseudocode in his paper actually shows you how to apply a steering force to an object, but uses a simple unrealistic point-mass physics system. If I’m right it should be enough to get steering behaviors up and running in Panda.

But if you want your vehicle to steer in a more physically realistic way, you would have to use Panda’s physics or PyODE to apply the steering force, instead of Reynolds’ point-mass physics. In the post I edited above I linked to the page in the Panda manual that shows you how to apply forces to physics bodies using Panda’s physics engine. They use the example of a gravity and a thrust force. I think you could apply a steering force in the same way. The problem then is that you have to integrate the physics model with Panda’s collision detection using PhysicsCollisionHandler. You can’t use the simple collision detection demonstrated in the Roaming Ralph sample code, which is what I’ve been relying on so far.