Platformer - Make an Enemy or Object Move Up and Down (No Extensions!)

I haven’t seen much of anything on how to make something move up and down without a bunch of variables or extensions, so I’m making a short post about it!

The only variable I needed was an Object Variable I called “Fly”. I made it a boolean to make it easier.

When the enemy Glider touches the GoUp object or the GoDown object, the boolean changes to true or false.

When the variable Fly is true, the enemy moves up. It has a negative force set to the Y axis.

When the variable Fly is false, the enemy moves down. It has a positive force set to the Y axis.

And done!

P.S - If the script for your enemy is in an External Event, make sure to link that to the scene. This is obvious, but I forget it all the time.

We need more posts like this. You can only learn so much from the Wiki. :smile:
This does the same. It uses a permanent force and checks the Y values instead of using a collision test. You could change everything to X for the other direction.

There are so many ways of doing things and we constantly change our techniques. I’m sure a room full of people would each have their own favorite way of doing something. It’s all good.

Challenge: Expand this to include 3 checkpoints or waypoints. No rules. With or without behaviors.

Thanks for the addition, Keith!

Anyone else is welcomed to contribute their ways, too!

That one sounds really useful, especially since i’ve heard that too much collision conditions can slow down the game’s performance because it’s checking collisions for every frame.

As for your challenge… IT’S ON! :triumph:

1 Like

I did the challenge, but I’m gonna post the results next month because it’s a mechanic for my game and I’ll reveal that in the next build.

1 Like

I can’t wait to see it. The basic way that I use is to give each object an ID and then either tween it from point to point or add a force toward the object with the next ID and then increase the target ID and repeat.

I played with the concept of using the nearest object while setting a visited Boolean for each point to remove them from the possible pick nearest object condition. It works but not consistently. It depends too much on the placement of the objects.

I forgot about the challenge and I thought you had as well. I was also playing with the same concept but as if they were planets. Instead of hitting the next point, it would slingshot around it. Maybe even gain speed as it gets closer. I forgot about it and didn’t get too far.

1 Like

Slingshot around it… that’d be cool!
If you ever get it to work better, show your work here. I’d love to see it.

1 Like

With a slight modification to this, you could use the toggle action for this, and only use one direction changing object.

1 Like

Would you like to add a screenshot of what the script could look like? :smiley:
It’d be cool if this thread could be like a collection of the ways we can make objects move.

Something along the lines of:

1 Like

That could be cool!

And then there would be the statements for the True and False states of the Boolean. It could actually be useful for times when you want movement that isn’t directly up/down or left/right, like diagonal movement!

Here’s a one up on that:

1 Like