Bounce Backwards with Enemy Collision?

kevinwynnskevinwynns Member, PRO Posts: 15

I'm working on a runner game in which my Player actor in perpetually in forward motion. However, I would like to have a behavior where the Player collides with an enemy, and bounces backwards a small amount (i.e. Castlevania). Simply giving the enemy a Bounciness Attribute doesn't work because the Player is still trying to move forward (creating a shaky, jittery effect). I currently have the Player's forward motion setup as a Linear Velocity Constrain Attribute. So I'm thinking I need to temporarily stop the forward linear velocity and replace it with a quick, short backwards linear velocity.... but I'm not totally sure. I setup a conditional Rule that says "when the Player collides with the Enemy: Timer for 2 seconds: Change Attribute, Player's Linear Velocity to -200." Buuuuut, I'm not sure that is setup correctly. Thoughts? Corrections? Ideas? :-)

Comments

  • JScottJScott Member Posts: 143

    What is your linear velocity constrained to? If you stop that temporarily on collision, then bounce should work. You should also be able to get your idea to work, but might not have the effect youre going for.

  • kevinwynnskevinwynns Member, PRO Posts: 15

    A pretty high speed. 700. I'm guessing I don't have the rules/behaviors setup correctly? Here's a screenshot.

  • JScottJScott Member Posts: 143

    What happens with that setup? Probably the constrain and change attribute conflict. Also, the timer set up won't work the way you want-I don;t think it will revert back after the time is up.
    If you want to keep the constrain to linear velocity, try constraining that to an attribute, and change the attribute as needed.

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited March 2016

    You need to cut off the constrain when the collide happens or that change attribute will only change the velocity for 300 this of a second or one code cycle before the constrain fires again. You need to have an attribute that triggers the constrain to stop and the change to happen and then set the attribute back. The collide rule you have will only fire when they are in a collide state as soon as they seperate the constrain will take back over.

  • DuesDues Member Posts: 1,159
    edited March 2016

    Is there a reason you are constraining your actors speed?
    You could just change the actors self.motion linear velocity X to 700 and have a rule that says:

    When actor overlaps or collides with (your obstacle)

    Change attribute: self.motion linear velocity X to 0
    Change attribute: self.position X to self.position X -(how many pixels you want the actor to bump back)
    Timer: After 1 seconds (or what you find a good amount of time) - run to completion
    Change attribute self.motion linear velocity X to 700.

Sign In or Register to comment.