x


Locking the Z-axis based on direction

I'm having a bit of trouble figuring out the maths for this one.

I have a series of nodes, each one has a position and direction, the player is always linked to one of these nodes, and can be anywhere on the line it describes (x direction) or above or below it (y direction), but cannot move into the foreground/background (z direction) relative to the direction the node is pointing I've got the moving in 1 axis working, but I need to snap the player to the relative Z of the object (no matter where they are on the line) Movement is done with the following code:

void Update()
{
    float Direction = Input.GetAxis("Horizontal");
    this.transform.position += (CurrentNode.transform.rotation * Vector3.forward) * Direction * Time.deltaTime * Speed;
}

this is not as simple as setting the z = 0, as that only works if the player is facing left/right relative to the game space.

I've thought about using 2 rays and finding their intersection point (Node ray is node position and node rotation, Player ray is Player Position* and Player rotation * Vector3.Left) but afaik the Ray class hasn't got an intersecting function.

Vector Math has never been my strong point sadly and I'd appreciate any help.

more ▼

asked Jul 01 '12 at 07:46 PM

Canazza gravatar image

Canazza
76 1 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:

x1042
x286
x185
x125
x62

asked: Jul 01 '12 at 07:46 PM

Seen: 372 times

Last Updated: Jul 01 '12 at 07:47 PM