Jumping and Falling

Hi everyone, Matt here,

I’ve just implemented a jump mechanic for my character, when the button is pressed he jumps upward.
The premise i used was taught by Peach in Techority:

**Set up a variable called, onFloor = true

when collision with the ground, do onFloor = true

When they hit a jump button, do onFloor = false.**

It works good, my character will go into a jump animation when jump is pressed.

Ideally though when he falls off a leadge without jumping he should still go into a fall animation (or later half of jump animation)

I’m having a hard time thinking of how i would track falling.

It seems i would need to track the characters .y Position?
And check if it’s getting lower (i.e: falling)

Unless there’s a way to setup a y.velocity tracker so when he’s standing his y.velocity is 0, when falling, as gravity pulls him his y.velorcity increases and if y.velocity > 0 then …

Any ideas on the subject?

I’m not sure the y.velocity idea is implementable?

Thanks
Matt.

[import]uid: 91798 topic_id: 18601 reply_id: 318601[/import]

Maybe what you are looking for is object:getLinearVelocity() ?

This returns the x and y components of the linear velocity. Typically if the y linear velocity is positive, the object is going down and if it is negative the object is going up. So if the y linear velocity of the character is positive while onFloor=true, then the object is most likely falling from a ledge.

  
local function checkFrame(event)  
 local vx, vy = character:getLinearVelocity()  
  
 if vy \> 0 and onFloor then  
 --FALLING  
 --could also compare against a slightly higher number than 0 to fine-tune it  
  
 end  
end  
  
Runtime:addEventListener("enterFrame",checkFrame)  
  

[import]uid: 94868 topic_id: 18601 reply_id: 71427[/import]

This does sound like exactly what i need,
Thanks for bringing that function to my eyes again.

And thakyou some more for your example code ^^ [import]uid: 91798 topic_id: 18601 reply_id: 71460[/import]

nice! glad to help. [import]uid: 94868 topic_id: 18601 reply_id: 71508[/import]