Jump to content
  • 0

Coding a projectile with gravitational properties


Moltar

Question

1 answer to this question

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.

 

[state 1005, VarAdd]

type = VarAdd

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

 

[state 1005, VelAdd]

type = VelAdd

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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...