Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (404)
games submitted by our members
Games in WIP (289)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [Solved]Polygon collision getting player stuck  (Read 690 times)
0 Members and 1 Guest are viewing this topic.
Offline 111poiss111

Senior Newbie





« Posted 2012-06-25 22:57:44 »

Hi.I made a game.It has tiledmap and polygons for collision detection.Apparently whenever I run into a polygon I get stuck.Hope someone can help me with that.I read from other topics but couldn't get it to work.
Source
I am planning to make this a small,2 player permadeath survival game.
Offline CyanPrime
« Reply #1 - Posted 2012-06-26 01:01:34 »

You'll need to show us the polygon collision part of your code only, and also tell us a little about it so we're not lost.
Offline Rorkien
« Reply #2 - Posted 2012-06-26 02:13:15 »



Basically, when you move the player and there is a collision, you also need to move him to the nearest free position, otherwise it'll really get stuck.
It is easier to implement if you are working with squares and few collidable moving entities.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Eli Delventhal
« League of Dukes »

JGO Kernel


Medals: 39
Projects: 12


Game Engineer


« Reply #3 - Posted 2012-06-26 02:18:46 »

Yes. It helps to think of it that he may never go into a situation where he is overlapping an object. Instead, when he wants to move, if that movement would cause him to overlap, only move him up until the collision. So before changing his position, you should see if the new position is valid first. Then you'll be fine.

See my work:
OTC Software
Offline 111poiss111

Senior Newbie





« Reply #4 - Posted 2012-06-26 18:07:49 »

Here are some pics of game with little descriptions
Right now as you can see,everything is made out of squares(tiled map) and game should have later few more moving entities(2 players and some creatures to kill).
I dont know how to check to see if tile is free to move on.
Offline Rorkien
« Reply #5 - Posted 2012-06-26 18:59:22 »

You can make a boolean method based on a X and Y position (in this case, your player entity position plus how much he moves every iteration), checking if there is something to collide with. If it returns true, it means something is already on that position.
Offline 111poiss111

Senior Newbie





« Reply #6 - Posted 2012-06-27 20:21:22 »

I came up with my own solution.I made 4 separate polygons(straight lines) for each direction and made them detect wether something is blocking from moving it in that direction or not.Right now it works beautifully.
Thanks for suggestions though.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (32 views)
2013-05-17 21:29:12

alaslipknot (40 views)
2013-05-16 21:24:48

gouessej (70 views)
2013-05-16 00:53:38

gouessej (69 views)
2013-05-16 00:17:58

theagentd (78 views)
2013-05-15 15:01:13

theagentd (73 views)
2013-05-15 15:00:54

StreetDoggy (113 views)
2013-05-14 15:56:26

kutucuk (137 views)
2013-05-12 17:10:36

kutucuk (136 views)
2013-05-12 15:36:09

UnluckyDevil (145 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.088 seconds with 21 queries.