x


Align an axis to a plane

I'm making a simple ICBM simulation. I want my "rocket" (more of a sphere) to move forwards along its forward axis (z) and face some point on a scale Earth with its y axis facing away from the target.

I figure I should be able to align the y axis to a plane (created from the center of the Earth, the launch point, and the target point). After that I can get it facing the way I want (in this case, away from the target).

Ideally I would then use its local x axis for pitch, and its local y axis for heading. In practice, I'd rotate locally around my x axis to nose down in an arc towards the target and rotate locally around my y axis to do course correction as I go.

On the image, if you were to rotate about 135 degrees around the z axis you'd get close to what I want (with green facing away from the viewer, and red facing to the left corner of the image).

The Green pin is the launch site, and the Red pin is the target.

alt text

// Determine where our next point is
Vector3 nextPosition = transform.position + velocity;

// Look at our new position. This gets our Forward vector pointing the right way
transform.LookAt(nextPosition);

// Turn so our YZ plane intersects the target, with Y facing away
// <-- HERE?

// Move to the new position
transform.position = nextPosition;
more ▼

asked Apr 22 '12 at 02:50 AM

JeffRosenberg gravatar image

JeffRosenberg
1 1 2 3

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2163
x322
x250
x195
x43

asked: Apr 22 '12 at 02:50 AM

Seen: 499 times

Last Updated: Apr 22 '12 at 02:50 AM