I’m working on a room inmy game which has some boxes(walls) that move back and forth blocking your way throgh the room. So what I have to do it place a box in between the 2 walls that are closing the way and jump over it while it holds the walls. In a diagram it looks like this:
XX → is a THE BOX I must place in between the walls 1 → start position of the walls 3 → is where it would go if there was no box blocking the way, the way would be closed 2 → is where it should stop if the box is in the way
in theory that’s how I would solve it:
void Update()
{
wall1 moveTo point3, wait, moveTo point1;
if(wall1 hit box1)
{
wall1 moveTo point2, wait, moveTo point3;
}
}
or
void Update()
{
wall1 moveTo point3, wait, moveTo point1;
if(wall1 hit box1 and DistanceTraveled < distFrom(point1 to point3))
{
wall1 moveTo point2, wait, moveTo point3;
}
}
not sure if I will need to calculate the distance traveled. I’ve been stuck on this for ages. Someone please save me