How do I use a objects position and linear velocity, and the “seeking” objects max acceleration speed to head off a target?

I am trying to make object 2 catch object 1, with physics

How do I use a objects position and linear velocity, and the “seeking” objects max acceleration speed to head off a target?

I am trying to make object 2 catch object 1, with physics

The high level is to take the object you are trying to reach, estimate its next position, and steer toward that position.

```
# estimatedTimeStep is the estimated time between frames in your game.
targetPt = target.worldPosition + target.linearVelocity * estimatedTimeStep
```

Once you have that target point, that is what you steer toward.

Here is a function I wrote to do exactly that. It returns the worldPosition of the point where the intersection should occur. A lot of the if/thens are checking to make sure an intersection is possible. (Note: need to import math)

own_pos = shooter position

target_pos = target position

target_v = target velocity

spd = projectile speed

```
def Intersect(own_pos, target_pos, target_v, spd):
x = target_pos[0] - own_pos[0]
y = target_pos[1] - own_pos[1]
z = target_pos[2] - own_pos[2]
vx = target_v[0]
vy = target_v[1]
vz = target_v[2]
a = vx*vx + vy*vy + vz*vz - spd*spd
b = 2 * (vx * x + vy * y + vz * z)
c = x * x + y * y + z * z
disc = (b * b) - 4 * a * c
if disc < 0:
pos = "None"
return (pos)
else:
c1 = (-b + math.sqrt(disc)) / (2 * a)
c2 = (-b - math.sqrt(disc)) / (2 * a)
if c1 < 0 and c2 < 0:
pos = "None"
return (pos)
else:
if c1 < c2 and c1 > 0:
c = c1
else:
c = c2
aim_x = c * vx + target_pos[0]
aim_y = c * vy + target_pos[1]
aim_z = c * vz + target_pos[2]
pos = [aim_x,aim_y,aim_z]
return (pos)
```

Example:

intersect = Intersect(own.worldPosition, target.worldPosition, target.worldLinearVelocity, 200)

lol,he catches it with one hand, and the other appears to be casting a spell?

so I am using own.linearVelocity.magnitude but this is not right because it’s not the speed in the direction of the target, it’s just it’s raw speed…

hrm…

how do I solve for these rbjs…

ThehatterStrange2.blend (539 KB)

I had this problem so I created an empty for each enemy that would be firing and placed this empty at the intersect position, then tracked to the empty.

That works, but then you have to change the position of the empty, and it is easier to forget the actuator, and just use the python function.

Aligning to a vect is more efficient. I updated my code to do that rather than an empty. Thanks!

Can you try plugging it into the 6 dof robot example?

I wonder how I can use the max and min angles of a 6dof joint to solve this?

I know this is one of the problems they face with robotics, I am going to dig.

edit:

Ok it looks like I have to build a armature, and then use it’s targeting and joint position and orientations as targets for “ForceMoveTo” and “TorqueTrackTo” and I will have a dynamic ball catching robot