Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (546)
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  
  Libgdx - How do I get the position of a fixture?  (Read 770 times)
0 Members and 1 Guest are viewing this topic.
Offline Ultroman

JGO Knight


Medals: 24
Projects: 1


Snappin' at snizzes since '83


« Posted 2013-01-10 17:15:36 »

TL;DR How do I get the friggin' position of a Fixture from a libgdx Contact object?

1  
2  
3  
Contact col = cols.get(i);
Entity entA = (Entity)col.getFixtureA().getBody().getUserData();
Entity entB = (Entity)col.getFixtureB().getBody().getUserData();


These are the first lines in my collision-code, the rest of which is otherwise unimportant and trivial.
I want to place an explosion in the middle of the fixture hit on my ship, if it is a killing shot.
As you can see, I can get the exact fixtures colliding from the Contact object, and they both may or may not be a part of a large body with many fixtures (in this case bullets and ships), and I can get the body it belongs to.

Problem: How do I find the position, or even better the middle, of the fixtures in my Contact object?

I can put userdata into the fixtures, but since I use Aurelien's BodyEditorLoader, it loads a bunch of fixtures, from which I get no information. They are just created. What I CAN get, is the childIndexNumber, which I presume is the index of this child in it's parent Body's fixtureList. So I canget get almost any information from anywhere...but not the position.

Solutions:
- Hardcode every offset of every fixture into them after they're loaded... (sucks)
- ...

- Jonas
Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #1 - Posted 2013-01-10 19:46:39 »

Eh... probably you want to have
Vector2 position = col.getFixtureA().getBody().getWorldCenter();
, which returns you the middle of your entity in meters relative to the origin of the world (I think it even accounts the center of mass, if I didn't mess up something...).

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline Ultroman

JGO Knight


Medals: 24
Projects: 1


Snappin' at snizzes since '83


« Reply #2 - Posted 2013-01-10 20:37:33 »

Yeah, that's good. But I want to know the position of every particular fixture in a ship, which might have up to 8 fixtures.

- Jonas
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #3 - Posted 2013-01-12 10:26:40 »

Yeah, that's good. But I want to know the position of every particular fixture in a ship, which might have up to 8 fixtures.

Then you'd use
contact.getFixtureA().getBody().getFixtureList();
, no? This would provide you all the "neighboring" fixtures of your ship.

I guess there is no other way, and this way doesn't seem like a hack to me Smiley

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline Ultroman

JGO Knight


Medals: 24
Projects: 1


Snappin' at snizzes since '83


« Reply #4 - Posted 2013-01-13 16:00:04 »

Well, that doesn't exactly give the positions of any of the fixtures, just a way, as you say, to find out which place in the Body's array the current fixture has. So I guess I have to create a list of all the debris-positions manually, and put it in the UserData.

Oh well, onwards to vengeance!!

- Jonas
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.

atombrot (23 views)
2014-08-19 09:29:53

Tekkerue (22 views)
2014-08-16 06:45:27

Tekkerue (21 views)
2014-08-16 06:22:17

Tekkerue (12 views)
2014-08-16 06:20:21

Tekkerue (19 views)
2014-08-16 06:12:11

Rayexar (57 views)
2014-08-11 02:49:23

BurntPizza (37 views)
2014-08-09 21:09:32

BurntPizza (29 views)
2014-08-08 02:01:56

Norakomi (36 views)
2014-08-06 19:49:38

BurntPizza (66 views)
2014-08-03 02:57:17
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!