I am trying to make a scrolling 2d game in Roblox. One problem I am facing is collisions with the player. In my game, the tiles move instead of the player to achieve the scrolling effect. I have searched all over the devforum to a solution but I’m yet to find one.
One of the things I’ve tried is this code here.
if self.PlayerPosition.X + self.Player.AbsoluteSize.X > Blocks.AbsolutePosition.X and self.PlayerPosition.X < Blocks.AbsolutePosition.X + Blocks.AbsoluteSize.X and self.Position.Y + self.Player.AbsoluteSize.Y > Blocks.AbsoluteSize.Y and self.Position.Y < Blocks.AbsolutePosition.Y + Blocks.AbsoluteSize.Y then
-- boom I hit a wall
end
PlayerPosition is a value I add to every time I move all the tiles, blocks being the tiles I’m trying to collide with.
Basically, I’m not too sure how to calculate for physics, especially with my techniques of moving the tiles.
If anyone knows how to help me, please leave an answer. Thanks!
Edit: I got the collision detection working but I don’t know how to make it like get out of the square it hit.
if self.PlayerPosition.X < FinalBlocksPosition.X + Blocks.AbsoluteSize.X and self.PlayerPosition.X + self.Player.AbsoluteSize.X > FinalBlocksPosition.X and self.PlayerPosition.Y < FinalBlocksPosition.Y + Blocks.AbsoluteSize.Y and self.PlayerPosition.Y + self.Player.AbsoluteSize.Y > FinalBlocksPosition.Y then
--Get out of block I hit
end