# Seeking in 3d Space

Is it possible to have the steering actuator seek along the Z axis as well? I’m working on a flying game and am struggling to seek to locations in 3d space. The edit object tracking doesn’t work as this doesn’t maintain character rotation (it flips the character upright when tracking. Not good for a flying game where you can be upside down).

Currently I’m trying to use a distance over time formula to calculate the force I need to either add to or subtract from gravity but it is math so it’s not working how I want. I was hoping for something simple. Any ideas?

Apply a force of 9.8 * mass of the object for anti-gravity:

``````

obj = cont.owner
obj.applyForce([0,0,9.8*obj.mass],0)

``````

Should work.

As for tracking in 3D, I wish I knew.

I was actually just coming on here to ask about the seek actuator as well. In one of my projects I made a waypoint following camera that uses the seek actuator to move from point to point around a scene and it works fine. I decided to go ahead and try to put something together for this week’s game making challenge and when I used the same process for a mesh it wouldn’t work as it only seeks on the X,Y plane. What I found out was when the mesh has collisions turned on it only seeks on the X/Y. When it doesn’t it will fly wherever you need it to. (I disabled gravity in my small game project because it is taking place in a fluid space…) Very frustrating differences in behavior.

I am thinking about making a no collisions empty object to go from waypoint to waypoint with the mesh attached to it as a child object. With a little luck that will work otherwise I am going to have to figure something else out and there isn’t a lot of time left.

I already have a force working against gravity. The problem is that dynamic objects only seek on the x/y plane, not up or down.

If my object will seek in 3d without collisions on, I might be able to make that work. I’ll give it a shot.

I have kind of a hacked work around. I get the height difference of the seek object and apply either upward or downward motion. I then check that distance every logic frame. When the difference is in the “Acceptable” range, I end the up/down motion.

It sort of works for now but not as well as seeking directly to the object would.

deleted

Ok so about volumetric A* _______ I can only find books on it and they are expensive.

Figured it out! After discussing a different issue in a separate post, sdfgeoff led me to the answer. Rather than trying to track to the point, simply use alignAxisToVect on the Y Axis. This will “track” to the object but prevent your character from rotating upright like the trackto actuator does. Finished code looks something like this:

``````
align_vect = own.getVectTo(pos)

own.alignAxisToVect(align_vect[1], 1)

own.setLinearVelocity([0.0, 100.0 ,0.0], True)

``````

pos = the intercept position I want to “seek” to.

Thanks everyone who helped!

Now that you have seeking, what about volumetric navmesh(path finding)?

The solution I implemented will only move to one specific point. I’m not sure how resource intensive aligning to vector is or if it would even work but I suppose you could just keep aligning the object to the vector every logic frame. (Maybe this is how the track actuator works currently???)

If you use “piece of candy”

So, on navigation, sets the next node to try and fly through,
then when it hits a invisible collision object at the center of the node, assign the next node,

this if done correctly and at the right speed, (bigger boxes = bigger rooms = bigger speed possible)

you could use A* to navigate a 3d space,

So
step 1 - Enemy spots player
step 2 - Enemy alerts nearby enemies of player current spotted location
step 3 - Enemies navigate nodes to get into the node where the player was spotted

This could be pretty cool, like metal gear solid in 3d

This could pathfind in games like descent,

I’ve been working on this for a few years now, I found alignAxisToVect a long time ago, but it tended to “snap” your object to its goal and would create very unrealistic motion. So I developed something a lot smoother.

``````
####
# Created by Robert Pearson, feel free to use and share, just include my name with it~
# convert a steering direction to a yaw pich and roll
# attempts to align the ship's up vector with up # urgency is a multiplier to control how fast turns should be exicuted
# ship is the KX_GameObject you will be applying the out put to # steering is a vector pointing in the desired direction
# up is a Vector that, if provided, the roll will attempt to keep the ship's  # +z axis parallel to
def turnToSteering(ship, steering, up=None):
# get the basis vectors for the ship
# X axis is assumed to be forward with +z up
shipX = Vector(ship.getAxisVect([1,0,0])) # forward
shipY = Vector(ship.getAxisVect([0,1,0])) # left
shipZ = Vector(ship.getAxisVect([0,0,1])) # up
direction = steering.normalized()
if up:
roll = -shipY.dot(up)
else:
roll= -shipY.dot(direction.cross(shipX))
pitch = -shipZ.dot(direction)
yaw = shipY.dot(direction)
if shipX.dot(Direction) &lt; 0:
# goal is behind so turn at maximums
if yaw &gt;0:
yaw = 1
else:
yaw = -1
if pitch &gt;0:
pitch = 1
else:
pitch = -1
return [roll,pich,yaw]

``````

Pitch, roll, and yaw will be between -1 and 1. I multiply them by the specific ship stats and apply them to local angularVelocity. For the steering vector I generally use goal.worldPosition-ship.worldPosition if the goal is an object. I have several different seeking behaviors to deal with different situations. I also have a collision avoidance setup using reciprocal velocity obstacles, if you have interest in it I could post it somewhere else since it doesn’t really fit with the topic here~