Right, so, I’m making a script which will orient one object onto an intercept course with another object. It takes into account the distances between the two objects and speeds at which they are moving. It’s kind of like a lead target for a missile: the missile is flying where it’s target is going to be and not where it currently is (a la track-to)

I’m all set up to a point: currently, the script calculates how far along the axis of movement of the target that the intercept should be… as in, the distance the object will have traveled before it is intercepted.

What I need is to take that arbitrary point (n units along the local Y axis) and convert it to a coordinate in world-space I can use either as a track-to target or with some other script which will point the intercepting craft in the right direction.

I’ve included a blend… it’ll probably help show what I mean.

### Attachments

hunterkillertest2.blend (184 KB)

Hi, Mathutils has a function that does exactly this I think

http://www.blender.org/documentation/248PythonDoc/Mathutils-module.html#LineIntersect

This works because the function uses the 2 imaginary lines as if they are infinite (so you can have very short lines and the trajectory will still be calculated right)

psudo code
ob1Loc, (ob1Loc+ob1linV)
ob2Loc, (ob2Loc+ob2linV)

from Mathutils import LineIntersect
isect = LineIntersect(ob1loc, ob1loc_and_linv, ob2loc, ob2loc_and_linv)

# Worldspace track point

track_pos = (isect[0] + isect[1])/2
trackOb.setPosition(track_pos)

Ideasman42:

Thanks for the suggestion

Okay, I had a long, LONG post here with a ton of questions about how your solution works, or rather WHY, but I think I can actually figure this out now… I just need to study up on the actual mathematics behind Vectors.

My real issue is I have no clue how vectors really work, exactly, but after staring at the Wikipedia page for a while I think it’s starting to get clear. I’m going to hard-copy the Wikipedia page on Vectors, take it home with me, and not come back until I get this worked out.

I will also try your suggestion, but I don’t think it’ll work for me because it seems to disregard the relative speeds of the two objects while accounting for the initial orientation of the Intercept object: both of these are undesirable traits.

However, I have another problem I’m working on on the side that will really benefit from Mathutils.LineIntersect, so Thank you.

Basically I’m making a series of scripts that function like ship navigation commands. If you’ve ever played EVE Online you’ve got an idea of what I’m going for: automated ship movement. Intercept Target is one of them, and I’ll be more than happy to post and describe the scripts as I get them working.

I’ll update this if I LineIntersect works, or if I figure it out another way.

Thanks!

Good thinking, ideasman! (or should I say, good idea?). Also, that’s a great link. It includes a function to turn x,y,z rotation into that crazy rotation matrix!!