How to make a person fling away?

In my game, I want to make it so that when the player steps on the ground, it explodes, and the player goes flying from the force in a random direction except down. I am having trouble with coding this.

Get a random number generator, that creates an angle, then add impulse.

Can you clarify how to turn the value into an angle?

The angle to bundle!

Where do you find it? I don’t see it in my bundles menu.

Wait never mind.

You could generate a random x and y?

I’m still confused. How do you impulse a random x and y? Look, I’m new to Flowlab. Or at least, newer than most good coders on Flowlab.

Randomise x and y then add to impulse

What do you think should be the range of my randomizer? My level is 70 blocks long, and 14 high.

Just try random ones, if it’s good, keep it, if not change it.

Does the game treat the random x and y in pixels?

I am pretty sure.

I feel the x and y method is a little too random. It would make more sense to send the player flying from the explosion origin, instead of teleporting to a different direction. Do you have any other way to work around the problem?

Hello!

There is an easy and harder way to apply a random directional force to a character.

The easier way is using a random to randomly generate a number from say, -10 - 10 and then hooking that to an X on an impulse.

At the same time you can use a random to generate a number from say 5 - 10 and hook that to the Y of the impulse.

Doing this will create a random force, but the force has a chance to be greater or weaker.

If you want to generate a force at a specific angle, you’re gonna have to use some trigonometry. Let me know if you’d like to do that - I promise it’s easier than you think :slight_smile:

2 Likes