Making a collision bounce straight up.

adeckeradecker Member Posts: 10
edited November -1 in Working with GS (Mac)
Ok so, i am making a game for iPhone like this one here: http://www.ferryhalim.com/orisinal/g3/bells.htm

I have tried everything i know how to do with collisions, but no matter what it shoots the actor in off the way where the collision happened. Any help anyone could provide would be nice! =)

Comments

  • rebumprebump Member Posts: 1,058
    Constrain the X position of the colliding actor(s) to their last known X position upon collision?
  • adeckeradecker Member Posts: 10
    more detail as i am new at this :P
  • rebumprebump Member Posts: 1,058
    Well, add a collision rule in the actors that you want to shoot straight up upon collision.

    In that rule (which fires upon collision), add a "Constrain" behavior to constrain the actors "X" position (i.e. self.Position.X) to the current value from the same value. So you may need to save it to an attribute first and then constrain it from the attribute value (if you constrain the self.Position.X to itself, you probably won't get the effect you want and you will be buring CPU cycles for no reason).

    You could then un-constrain upon some other event (i.e. just set it back to a value rather than using another constrain).

    Hope that made sense.
  • adeckeradecker Member Posts: 10
    OK, thank you but could you go more in debt on the save it to an attribute part? sorry i just started yesterday
  • rebumprebump Member Posts: 1,058
    Well, create an actor attribute (call it "LastXBeforeCollision" or something) that is integer (or real) and you use the "Change Attribute" behavior to save the "self.Position.X" value into it.

    Be aware that this method will force a straight up movement after a collision and its perceived speed may vary a little based on the original angle of deflection of the collision before being constrained.
  • adeckeradecker Member Posts: 10
    Well i tried it. It didnt work. It still bounces off the direction that it hit on.
  • rebumprebump Member Posts: 1,058
    Sorry, I forgot you probably need to zero out the actor's X velocity value too. And if you don't want it rotating, the angular velocity as well. You could even manually set the Y velocity if you want to control the speed it moves upwards to keep appearances consistent. All the velocity stuff is under "self.Motion..." if I recall correctly.

    If you alter the velocities as above, you probably won't even need to mess with the X position (i.e. no need to constrain it).

    Sorry, it's hard to remember all this when you are on a non-Mac at work and don't have GS in front of you to peek at or mess with.
  • adeckeradecker Member Posts: 10
    OkAt school righ now I'll give it a shoT when I get home
Sign In or Register to comment.