Jumping with a rectangle

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.
Post Reply
User avatar
iPoisonxL
Party member
Posts: 227
Joined: Wed Feb 06, 2013 3:53 am
Location: Australia
Contact:

Jumping with a rectangle

Post by iPoisonxL »

Hello! Just a quick question, how do I eliminate the tiniest bit of lag I get when I have a rectangle jump and land?

To clarify:

Here's some code

Code: Select all

if(self.y>=400-self.h)then --if y is greater than the ground height
        self.yvel = 0
        self.y = 400 - self.h
        self.onGround = true
    else
        self.y = self.y + (self.yvel * dt)
        self.yvel = self.yvel + 9.8
    end
When the player lands on the ground, he goes through the ground for 1 frame exactly. This happens because he would be, say, 1 pixel from the ground when he is moving let's say 2 pixels a frame. So he goes 1 pixel past the ground for 1 frame then gets rectified because of the line that says "self.y = 400 - self.h". How do I get rid of him going through the ground for a frame?

Code: Select all

      L
    L Ö
    Ö V
L Ö V E
Ö B E
V E
E Y
Website
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: Jumping with a rectangle

Post by Azhukar »

By adding velocity to the check.

Code: Select all

if(self.y+self.yvel>=400-self.h)then
User avatar
iPoisonxL
Party member
Posts: 227
Joined: Wed Feb 06, 2013 3:53 am
Location: Australia
Contact:

Re: Jumping with a rectangle

Post by iPoisonxL »

Azhukar wrote:By adding velocity to the check.

Code: Select all

if(self.y+self.yvel>=400-self.h)then
It just does this...

Image

Code: Select all

      L
    L Ö
    Ö V
L Ö V E
Ö B E
V E
E Y
Website
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: Jumping with a rectangle

Post by Azhukar »

Code: Select all

if(self.y+self.yvel*dt>=400-self.h)then
Forgot * dt
User avatar
iPoisonxL
Party member
Posts: 227
Joined: Wed Feb 06, 2013 3:53 am
Location: Australia
Contact:

Re: Jumping with a rectangle

Post by iPoisonxL »

Azhukar wrote:

Code: Select all

if(self.y+self.yvel*dt>=400-self.h)then
Forgot * dt
Thank you!! I don't think my brain is working too well I've been doing too much Haskell.

myBrain :: Haskell -> Lua

exception: cannot get type Haskell and return Lua

Code: Select all

      L
    L Ö
    Ö V
L Ö V E
Ö B E
V E
E Y
Website
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Jumping with a rectangle

Post by kikito »

I think Lua and Haskell are like two extremes of the spectrum in programming. Lua is small and "loose", while Haskell is big and "correct".

I tried Haskell once, but was a bit exhausted after a while. I'm guessing it gets easier after you climb the initial learning curve, but I gave up before. What are you using / have you used to go over that curve?

Also, I will take this opportunity to plug my library, bump, here. It seems to do exactly what you are doing manually, in a generalized way (it calculates the point where the rectangle will impact and returns it to you).
When I write def I mean function.
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: Jumping with a rectangle

Post by Azhukar »

I think functional programming is a waste of effort.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Jumping with a rectangle

Post by kikito »

Well, even John Carmack needed years to warm up to it, and he's a genius, so I don't expect everyone to suddenly accept it :ultraglee: . Nevertheless, try to keep an open mind towards it; it has some very valid merits.
When I write def I mean function.
User avatar
iPoisonxL
Party member
Posts: 227
Joined: Wed Feb 06, 2013 3:53 am
Location: Australia
Contact:

Re: Jumping with a rectangle

Post by iPoisonxL »

I'm using http://learnyouahaskell.com, kikito. It's a very good guide but I've had to go to the IRC chat twice so far to get some basic understanding on function currying (all functions take one parameter, but return a function that take another etc) and other stuff that is totally off for programming paradigms. But I feel haskell is very, very powerful, and definitely not a waste of time cause of the whole lazy thing which lets you operate on INFINITE lists, without having a stack overflow or performance issues. And you can make code that looks really cool like this for example:

Code: Select all

 (<!!) :: (Eq a) => a -> [a] -> Bool
    _  <!! []  = False
    x <!! (l:ls) =
        if l == x then True else x <!! ls
or this:

Code: Select all

sumOddSquaresUnder :: Integer -> Integer
sumOddSquaresUnder n = sum . takeWhile (<n) . filter odd . map (^2) $ [1..]
Woohoo for Haskell

Note, I'm only like halfway done all the tutorials, I've still got a bit to do

Code: Select all

      L
    L Ö
    Ö V
L Ö V E
Ö B E
V E
E Y
Website
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 8 guests