jump problems

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: jump problems

Post by kikito »

Ranguna259 wrote: This, this is what causes most of the bugs, in my collision code I used this for everything. Bad times..
But since your just using this for static objects I think it's fine, but how can two static objects collide, Probably only if the coder coded two static objects on top of each other by mistake, right ?
Not necessarily. There are scenarios where static objects must be spawned on top of others. For example, explosions. They are created suddently and they affect a more or less great area - potentially overlapping with existing objects. But yes, it could happen that a coder moves an object around (with world:move) without checking for collisions first (with world:check), or resolving the collisions poorly.
Ranguna259 wrote: Interesting approach, I actually use this algorithm in my geometry lib to check intersection points between a line and rectangles. I never thought about using it to resolve collisions.
The idea is not mine. I took it from Collision Detection for Dummies. I just decided that I didn't want to use lots of vectors, so I stuck with AABBs instead of polygons.
Ranguna259 wrote:I use [wiki]love.physics.newEdgeShape[/wiki] and then I attach all EdgeShapes to a single static body, thank you Omar for telling me how this is done ;)
I don't like having to use edge shapes. They look like a cop-out :cool: . But whatever works for everyone. Your gif looks cool :)
When I write def I mean function.
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: jump problems

Post by Ranguna259 »

kikito wrote: Not necessarily. There are scenarios where static objects must be spawned on top of others. For example, explosions. They are created suddently and they affect a more or less great area - potentially overlapping with existing objects. But yes, it could happen that a coder moves an object around (with world:move) without checking for collisions first (with world:check), or resolving the collisions poorly.
Oh yeah, sudden creation of static objects, didn't thought of that.
kikito wrote:The idea is not mine. I took it from Collision Detection for Dummies. I just decided that I didn't want to use lots of vectors, so I stuck with AABBs instead of polygons.
Interesting article, not that I'm thinking on rebooting my physics project but still, it's knowledge and knowladge is good :P
kikito wrote:I don't like having to use edge shapes. They look like a cop-out :cool: . But whatever works for everyone. Your gif looks cool :)
Well, they work so it's fine with me :megagrin:
Thank you, soon to be in Projects and Demos section.
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: jump problems

Post by micha »

@elsalvador: let's get back to your initial question. So far, your approach is fine. All you have to do, is fix your internal logic a little bit.

So, this is the line of code, that does the jumping:

Code: Select all

if not (l.direction == "jump") and k("j") then  l.yvel = jumpv ; l.direction= "jump" end
What it does is, it checks if the direction is not "jump" and if the key is pressed. The reason, why you get the flying-effect when going left or right, is that if you press left or right then l.direction is set to "left" or "right" and it is not "jump" anymore. So let's forget about the l.direction variable. The does not tell us enough about the player's state. So, first remove this line and then add these ones:

Code: Select all

-- in the initialization:
l.canJump = true

-- in the update:
if l.y >= floor - l.h then
  l.y= floor - l.h
  l.yvel= 0
  l.canJump = true
end

-- in the keypressed:
function p:keypressed(key)
  if key == 'j' and l.canJump then
    l.yvel = jumpv
    l.canJump = false
  end
end
elsalvador
Citizen
Posts: 54
Joined: Thu Oct 24, 2013 1:29 am

Re: jump problems

Post by elsalvador »

okay so what you say is that not everything have to go under love.update???if i press key it will make the jump??? an not ruin my i.direction??
let me give it a try and let see if it works i kind of confuse with the update i see map collisions under keypressed wonder how will i do it with update if i want smooth movement and not block by block so the update in this as well makes me think... and thanks for the help if any problems ill get back again :)
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: jump problems

Post by micha »

The only thing that you should put into the keypressed-event is the start of the jump, because the start of the jump happens only in one moment in time. Of course, the rest of the jump, namely moving through the air, is handled in the update-event.
elsalvador
Citizen
Posts: 54
Joined: Thu Oct 24, 2013 1:29 am

Re: jump problems

Post by elsalvador »

Thanks for the help i just learned a little bit about jump action but here is the problem after doing what you guys told me i found that
the directions of the games are not accurate and here can become a bug in future for my project i tried my best but i cant understand how to use keypressed and released for direction?
here its the update and i am sure I did something wrong..because my directions are not 100% and i am planning to use them for more stuff

i still want to show its jumping while its actually jumping and show stand while stand and walking both direction but how to use the pressed and released ????its tricky for sure..

for sure the only way to learn its to ask and ask the pro-programmers like you guys :)
Attachments
updatejump.love
(6.31 KiB) Downloaded 49 times
User avatar
murks
Party member
Posts: 185
Joined: Tue Jun 03, 2014 4:18 pm

Re: jump problems

Post by murks »

Thanks a lot Micha for your jump explanation, I guess it would have taken me ages to implement this without some guidance. I implemented 'Mario style' jumping now, it still needs a lot of tweaking but it works!
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests