• 0

# Coding a projectile with gravitational properties

## Question

If you want to code a projectile (such as Mario's fireballs), and you also want them to have gravitational properties when initiated, how would you be able to code that?

## Recommended Posts

• 0

Easy enough.

Give a var to your projectile. Helpers can have their own vars, you won't use a var from your char.

trigger1 = !time

var(0) = 1

persistent = 0

Of course you must give a negative y vel to your fireball and a gravity value, and set the statetype as aerial..

[state 1005, VelSet]

type = VelSet

trigger1 = !time

x = -10

y = -10

[state 1005, StateTypeSet]

type = StateTypeSet

trigger1 = 1

statetype = A

movetype = A

physics = N

trigger1 = statetype = A

y = 1

Then, when the fireball reaches the floor...

[state 1005, ChangeState]

type = ChangeState

;trigger1 = vel y > 0

trigger1 = pos y > -vel y...

... if your ball is in the state 1005, make so that it goes to the state 1005 AGAIN.

...

[state 1005, ChangeState]

type = ChangeState

trigger1 = vel y > 0

trigger1 = pos y > -vel y

value = 1005

ctrl = 0

Keep in mind that since the fireball is at the beginning of the state 1005 it will add 1 to its var again. Every time the fireball returns to the state 1005 the var will add a value of 1.

Now there's that thing with velset on the beginning of the code. If you want to make the fireball bounces less and less each time it reaches the floor, change that velset code to something like this:

[state 1005, VelSet]

type = VelSet

trigger1 = !time

x = -10

y = ifelse(var(0) < 1, -10, 0.5 * vel x)

With this code, the next time the fireball bounces it will have a y speed of -5, then -2.5 in the next bounce, then -1.25, then -0.625...

The code is among these lines.

## Create an account

Register a new account

×

• Back

• #### Mugen Software

• Back
• Mugen Software

• Back