Making a Rotating platform in a Platform game

BlitzMax Forums/BlitzMax Programming/Making a Rotating platform in a Platform game

Rico(Posted 2011) [#1]
I just made a boat in my platform game which rotates/tips a bit in the water. the main character can stand on top of the boat. i have never made a platfrom that rotates before so i wanted to ask for tips before i attempt it. i can draw it ok using SetRotation its just the collision detection i need help with.

whats the best way of detecting if the main character has collided with the top of the boat?. i could do imagecollide but i thought it might be more efficent to check for a collision between the main character's box and the standing surface on the boat. so i suppose between a rectangle and a line. does anyone have a function for this?

im planning to use trig functions to determine the position of the line (standing surface) as it rotates, but im not the best with these things. im sure once the man is actually on the boat i can move him about pretty easily using trig. thanks for any help or tips! :)


Jesse(Posted 2011) [#2]
you can use polygon collision. One way of doing it is by following the principle in this thread:
http://www.blitzmax.com/Community/posts.php?topic=93221#1066645


Rico(Posted 2011) [#3]
Thanks very much Jesse, i like that program a lot. so to check a character square against the rotating polygon - i just check each corner point against the rotating polygon?


Jesse(Posted 2011) [#4]
Yea. something like this:


Last edited 2011


Rico(Posted 2011) [#5]
Thanks very much Jesse, i have already implemeneted the rotating platfrom in my game but your code looks much neater! :D

in my game the main character always stays vertical so he doesnt rotate with the platform. i like your version though.

i have found a problem though with my version and i presume it would happen in yours too. when the platform is rotated at quite a steep angle - a collision is not detected when it should be if the man lands on the end of the platform. this is because the points that are checked for collision are on either side of the corner he lands on. i dont think putting an extra point in the middle of the man's character sqaure at the bottom would help much - so am i thinking i need to check the whole of the bottom of the man's character square against the platform.

do you have a function that can detect a collision between a line and a rectangle?, where the rectangle could be rotated. so i suppose i really want onr that detects a collision between a line and a polygon? i could then just check the horizontal line at the bottom of my man against the platform.


Jesse(Posted 2011) [#6]

do you have a function that can detect a collision between a line and a rectangle?,


No, but i believe Warpy posted one in the code archives. I can't remember if it works with rotated rectangles but I believe it does.


Rico(Posted 2011) [#7]
thanks Jesse. i have found this for line and polygon:

http://www.blitzbasic.com/codearcs/codearcs.php?code=1676


Rico(Posted 2011) [#8]
i fixed that problem, but i thought 'how would they have done it in the old days?'. so i just added a couple of IF statements to check if the character square was over each corner of the boat and if it was then checked to see if the character-square was overlapping vertically with the y-position of that corner. very easy fix and no need for a polygon/line collision check.