Help Bouncing at the same height

Dazza006Dazza006 Member Posts: 248
edited June 2012 in Working with GS (PC)
hi,

I have been working on my game now for about a month and I'm trying to get my actor to bounce at the same height every bounce.

I have put a rule in the actor so it can't bounce over a certain height which works but when I jump on a platform it takes a couple of bounces to get back to the highest bounce.

I'm trying to make the actor bounce straight to the highest bounce first touch.

can anyone help me with this a would appreciate it.

Best Answers

  • domeniusdomenius Posts: 108
    Accepted Answer
    Remove friction as well as drag or angular drag. Also ensure that you have no scene gravity. Aside from that, I would increase the restitution (bounciness) until it works. How are you limiting the actors jump height? Your basic problem is that if you are jumping to a higher platform than you started on, your actor will not have as much velocity when it hits the platform as it did before since it's about halfway through its return to speed from dropping. This reduces the return height as your next bounce starts with a reduced velocity. A better way (IMO) would be to record your starting pos and then use an ease in interpolate to reach the desired height then another ease in to return to your original height. Do this by directly modifying the self.pos.y to, say, startY+1000 (or your desired bounce height in pixels) on the first interpolate and then startY on the second interpolate to return to base height. You'd probably want to wrap that inside a rule such as if collide with ground/obstacle, and place your interpolate inside the else section of that rule. That way you either hit the ground, or stop when you hit another object. If you do it this way, you can force the actor to reach a specific height, and then stop, then drop back down. This won't work if you rely on the physics library for your game logic, but if you use it exclusively for a straight up and down bounce, this would be more efficient than the physics lib as well. I prefer to give the engine a finite destination and then let it figure out how fast we need to move rather than specify a velocity and hope it reaches the desired height. If it makes more sense to change velocity instead, you could use this same idea and modify velocity instead of position, that way you don't have to do your own work for any other physics-type actions available. Avoid using physics if you can, it's slow.

    Also, don't use a timer for the second interpolate, have a boolean trigger that states if self.pos.y = startY+(desired height) then trigger is true. Fire your second interpolate on this trigger and turn it off when you've returned to solid ground (probably inside the unused section of the rule we wrapped the second interpolate in).

    Hope this helps, if not I may be able to give a better solution if I better understood the context this is used in. Does this actor also take direct user input? Or are we talking about an object that constantly moves?
  • jckmcgrawjckmcgraw Posts: 647
    Accepted Answer
    @Dazza006

    Have all physics self attributes 0 in all actors that will/might collide with each other, as well as the scene's gravity to 0.

    Rule inside ball: accelerate down at around 1,300 (you can change it to your likings)

    Rule: when ball overlaps or collides with actor "ground", change self.motion.linear.velocity.y to somewhere around 1,000.

    Now, the ball (main actor) will bounce at exactly the same height every time regardless of how high it falls from. The reason you don't want to use the "bounciness" or "restitution" for something like this is because those are physics attributes, and what you are doing would not happen realistically without another force pushing upwards.

    Hope this helps,
    Jack McGraw

Answers

  • jn2002dkjn2002dk Member Posts: 102
    How are you bouncing your actor?

    If you simply set linear velocity it should work
  • Dazza006Dazza006 Member Posts: 248
    I have made the bounciness 2 and the platforms the actor collides with 2.
    Also on the actor a rule: linear velocity Y is greater than 1000 change attribute self velocity Y to 1000 this way when the actor bounces over 1000 the actors velocity changes to 1000 so the actor won't bounce over 1000. this seems to work but when the actor jumps on a platform he takes two bounces to get to 1000. I have tried putting some sort of acceleration on when the actor collides with the platform but I can't seem to get it to work right.
    do you know a better way to get this to work?
Sign In or Register to comment.