Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (789)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (864)
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 3307 times)
0 Members and 1 Guest are viewing this topic.
Offline 111poiss111

Senior Newbie

« Posted 2012-06-25 20: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.
I am planning to make this a small,2 player permadeath survival game.
Offline CyanPrime
« Reply #1 - Posted 2012-06-25 23: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 00: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

JGO Kernel

Medals: 42
Projects: 11
Exp: 10 years

Game Engineer

« Reply #3 - Posted 2012-06-26 00: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 16: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 16: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 18: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  

hadezbladez (2617 views)
2018-11-16 13:46:03

hadezbladez (944 views)
2018-11-16 13:41:33

hadezbladez (2571 views)
2018-11-16 13:35:35

hadezbladez (509 views)
2018-11-16 13:32:03

EgonOlsen (3738 views)
2018-06-10 19:43:48

EgonOlsen (4136 views)
2018-06-10 19:43:44

EgonOlsen (2496 views)
2018-06-10 19:43:20

DesertCoockie (3303 views)
2018-05-13 18:23:11

nelsongames (3399 views)
2018-04-24 18:15:36

nelsongames (4376 views)
2018-04-24 18:14:32
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
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!