collide with absolute edge of actor
Hi guys, I've searched for an answer on this site but only found one thread which didn't really help my situation.
I have been working on a little feature in which a character is able to hit the top of an actor but if it hits the side or bottom, a different action is triggered. I have followed what seemed like a very good tutorial online (jamie-cross.net) to achieve this but there is a problem with the precision of the collision detection.
Here is a quick summary of my function and the problem it has been experiencing:
- I set up two global real attributes, charBottom and enemyTop
- Constrained char bottom to player bottom; self.position.y - (self.size.height /2) +10
- Constrained enemyTop to enemy top; self.position.y + (self.size.height /2)
set up rules on character:
- if character collides with enemy then:
- if charBottom >= enemyTop
- self.motion.linearVelocity.y to 250
- if character collides with enemy then:
- if charBottom < enemyTop
- pause game
I set it to pause game since originally it was set to bounce, but I noticed it was bouncing where the linearVelocity action should be triggering (an inconsistent bounce height gave me a clue to this)
I had to increase the amount of pixel lines on the first constrained attribute from 5 to 10, this lessened the issue but it still persists. Increasing it further would help more but the 10 pixels fudge is already far less accurate than I would like to have.
Has anyone else run into this problem and found a work around which enables you to keep a high precision?
EDIT: Forgot to mention that when I hit the top of an enemy, about 9 times out of 10 all is fine but sometimes (seemingly randomly) the second function is hit and the game pauses.
I have been working on a little feature in which a character is able to hit the top of an actor but if it hits the side or bottom, a different action is triggered. I have followed what seemed like a very good tutorial online (jamie-cross.net) to achieve this but there is a problem with the precision of the collision detection.
Here is a quick summary of my function and the problem it has been experiencing:
- I set up two global real attributes, charBottom and enemyTop
- Constrained char bottom to player bottom; self.position.y - (self.size.height /2) +10
- Constrained enemyTop to enemy top; self.position.y + (self.size.height /2)
set up rules on character:
- if character collides with enemy then:
- if charBottom >= enemyTop
- self.motion.linearVelocity.y to 250
- if character collides with enemy then:
- if charBottom < enemyTop
- pause game
I set it to pause game since originally it was set to bounce, but I noticed it was bouncing where the linearVelocity action should be triggering (an inconsistent bounce height gave me a clue to this)
I had to increase the amount of pixel lines on the first constrained attribute from 5 to 10, this lessened the issue but it still persists. Increasing it further would help more but the 10 pixels fudge is already far less accurate than I would like to have.
Has anyone else run into this problem and found a work around which enables you to keep a high precision?
EDIT: Forgot to mention that when I hit the top of an enemy, about 9 times out of 10 all is fine but sometimes (seemingly randomly) the second function is hit and the game pauses.
Best Answer
-
AppTaco Posts: 125
Hello,
The "bounce when collide" behavior just makes it so that the actors don't overlap at all. The bounce effect is immediately overwritten by the change attribute self.velocity.y to 250. I made a little template to demonstrate.
https://www.dropbox.com/s/jdv2ebgww34kcjy/Jump on Enemy.zip
Answers
If there is a way of specifying a constant bounce distance then this should indeed solve my problem but being a noob to gamesalad I am unaware of any such method.