Bump/Jump Effect

● ARCHIVED · READ-ONLY
Started by Evgenij 3 posts View original ↗
  1. Hi, Im wondering how I can do a jump effect. Maybe there is a formula for this.

    I want to make a text appear above an Event for example, this text should go up a little bit and then down again. It would visually look like the text is jumping.

    The way Im thinking off would be making two counter variables one that will go up from 0-30 and one that would go down from 30-0

    If I multiply both I would get values from 0-255 and 255-0, this would be a solution, but Im wondering if there is another way for this kind of calculation, maybe without using two variables.

    Thanks for all answers
  2. A smooth jump would require tweening, or a physics emulation (aka a gravity constant, a speed variable, and a check whether the y coordinate of your text sprite is >= the original y it started at).


    You can check out CaptainJet's tween script, found on pastebin here. Find the module Ease, and then find it's sub-module Bounce::InOut. That should do ya good on a decent jump / bounce calculation.
  3. This is the basic idea.

    #Initializing the effect. Put it inside some initialization method or something.@speed = -8@gravity = 0.5@base_y = 120 ### (...) #Updating the effect. This goes inside some updating method.#Change self to the variable containing the object (Sprite, etc) if it is controlled by another class.self.y += @speedif(self.y >= @base_y)  @speed *= -1  self.y = @base_yend@speed += @gravity@speed = 8 if(@speed > 8)@speed = -8 if(@speed < -8)The first part (the initialization) needs to be called outside of the updating. If not, the @speed would be constantly reset. It uses the same variables FenixFyreX mentioned, having a @speed, a @gravity and a @base_y position, something that will act like an imaginary/logic ground where the text will collide and bounce (?).

    Then the second part commits the movement (adds the speed to the position), checks if the new position has overlapped our bound, and if it does, it inverts the @speed and makes sure the text never goes below our vertical boundary. Then we apply @gravity deacceleration, and apply some limits to the @speed.

    EDIT: Ah! If you want to make it bump just once, no bouncing, then just change @speed *= -1 to @speed = 0