PlayMaker Help & Tips > PlayMaker Help

how to find direction of travel

(1/1)

foxhideous:
Hi everyone!

  I'm pretty new to Unity and playmaker so please bear with me. I'm creating a marble rolling game(similar to marble madness) and using physics(add torque) to control the marble. What I want to do is find out what direction the marble is heading towards so that I can position the camera slighty ahead of it. I was thinking of getting the Y angle from the (get rotation action) but for some reason it's not working right. The numbers seem to be jumping all over. I started experimenting with other actions but nothing seems to help. Any clues on how I could get the heading?

Thanks! :)

jeanfabre:
Hi,

 you can find the direction of travel by implementing the following procedure:

 you need three vector variables, the current position, the last position and the direction

One each update:

1: store the current position
2:Get the direction vector by substracting the current position by the last position,
3: inject the current position to the last position variable

When that fsm starts, don't forget to set the current AND the last position to the current position of the ball, else the first time your procedure will run, the direction vector will be wrong.

Use that direction vector as a target for your camera to look at.

Does that make sense?

bye,

 Jean

Navigation

[0] Message Index

Go to full version