0
\$\begingroup\$

I have a moving cube that, when it moves over an arrow, should change its direction to the direction of that arrow. What would I need to do in order to accomplish this?

enter image description here

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Is this question about detecting intersection with the arrows or about changing the cube's movement angle? How is each arrow storing its angle? \$\endgroup\$
    – Anko
    Sep 13, 2014 at 19:05
  • \$\begingroup\$ I want to create a simple code motion I just want my cube to detect the arrow and start moving in the direction it indicates. \$\endgroup\$ Sep 13, 2014 at 22:31

1 Answer 1

0
\$\begingroup\$

Depending on how much arrows you have, you could simply check the distance from the arrows center to the cubes center and do something if it is below a threshhold.

//I assume ARROWS to hold the Transform of all arrows
foreach ( Transform arrow in ARROWS)
{
    if ( (arrow.position - cube.position).magnitude  <= (Time.fixedDeltaTime * cube.speed) / 2)
        cube.changeDirection (arrow.direction);
        break;
}

This will ensure, that the cube moves as close as possible to an arrow before changing direction.

ATTENTION:
I totally made up the fields speed, changeDirection () and direction. You have to define them yourself or derive them from the existing data.

The best place for this would most likely be the fixedUpdate() of your cube.

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .