This site requires JavaScript, please enable it in your browser!
Greenfoot back
fejfo
fejfo wrote ...

2015/2/21

problem with good gravity/collision detection

fejfo fejfo

2015/2/21

#
I have tried to make a good gravity engine for a game but I have a problem with the collision detection. manly for testing if you're at the top of a block or if you're at a side of the block. everything I have tried results in wall climbing or an error
Riculo Riculo

2015/2/21

#
I don't know...
danpost danpost

2015/2/21

#
You are probably moving both horizontally and vertically at the same time -- using something like 'setLocation(getX()+dx, getY()+dy)'. By doing so, any collision cannot be easily determined from where (which direction of movement caused the collision). Separate the horizontal movement from the vertical movement and perform collision checking with each individually. For an example, look at my Jump and Run Demo w/Moving Platform demo. Just run it on the site and click the 'Who' button along the bottom of the window. The 'up' and 'down' keys will scroll the text as well as dragging the handle of the scrollbar along the right edge.
fejfo fejfo

2015/2/22

#
thanks!
You need to login to post a reply.