Sign in to follow this  
Kokos

P2 bodies on (rotated) sprites within groups

Recommended Posts

Hey,

I'm building a top-down parking game, for this game we have levels in JSON which (among other things) determines where the player spawns and at what angle. The player consists of three sprites and three bodies (car and two front wheels) that are positioned relatively to each other.

Everything goes well, until I try to spawn the car at an angle, because suddenly I no longer know the x and y coordinates of where to spawn the wheels, and it's a bunch of math to figure that out especially as phaser groups fix this problem.

Enter example of my problem #1: https://jsfiddle.net/tv4j4tw1/

What I did here is simply create two sprites in a group, positioned them, positioned the group, and then added a body to the sprites. However the bodies spawn completely out of place. If this actually worked properly I'd have no issues. You can ask why do you even need a group here? I do because of the angles mentioned above, if this group would get an angle it'd be a lot harder to figure out the coordinates of the squares.

Now we go into where I tried to hack my way out of this problem: https://jsfiddle.net/tv4j4tw1/1/

Ha! This works, I use the group to position the sprites, and then take the sprites out of the group and position them according to their world position while in the group. It's hacky, but I can live with it.

Sadly it stops working once I add the angle (which is the whole reason I'm doing this weird stuff): https://jsfiddle.net/tv4j4tw1/2/

The world position is wrong, and the squares still end up in the wrong place. 

 

So, I hope I'm doing something fundamentally wrong and getting the hack to work is a silly idea. Halp.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.