Reputation: 31
I am making a game that uses Doodle Jump like jumping where you can go through platforms if you're moving up but not if you're moving down, except there is a ground platform that is always there. You can't ever get below this ground platform. However, if the player is moving fast enough the player goes through the ground platform like in the picture:
Even more confusing is that this only happens about 1 in 5 times of doing a jump and only happens to the ground platform, which is identical to the higher platforms. Another thing that is unusual is that if the player is below the ground, it still properly detects hitting enemies as if it were on the ground even though the image is fully below ground, which makes me think the physics body and the image somehow aren't synchronized.
I am using static SKPhysicsBody
s to represent that platforms & ground and a dynamic SKPhysicsBody
to represent the player. I have the platform.physicsBody?.collisionBitMask = PhysicsCategory.Player
for the platforms, and player.physicsBody?.collisionBitMask = PhysicsCategory.Platforms
for the player. I also have physicsBody?.usesPreciseCollisionDetection = true
for both. Both use rectangles to implement their physics bodies, with the platforms having a thickness of 2.
I've tried everything and nothing seems to be able to fix this. I even tried tacking in checking for this is didSimulatePhysics()
.
override func didSimulatePhysics() {
if self.player.position.y <= 1/7 * size.height {
player.position.y = 1/7*size.height //+ CGFloat(yScaler) * size.height
if let body = player.physicsBody {
if body.velocity.dy < 0 {
self.player.physicsBody?.velocity.dy = 0
}
}
}
}
didSimulatePhysics()
properly detects when this happens, yet when I try adjusting player.position.y it doesn't update it at all and remains trapped below the ground!
Any ideas on what's going on here? I'm at wits end. Thank you in advance!
Upvotes: 0
Views: 345