Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (117)
games submitted by our members
Games in WIP (563)
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 1076 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.
Source
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  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

radar3301 (12 views)
2014-09-21 23:33:17

BurntPizza (31 views)
2014-09-21 02:42:18

BurntPizza (22 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (28 views)
2014-09-20 20:14:06

BurntPizza (33 views)
2014-09-19 03:14:18

Dwinin (48 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (103 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!