phisics - moving the surrounding world around a the player object

I’m using the physics engine, and currently have a spaceship object that you can thrust around the screen. It’s subject to gravity and falls naturally when no thrust is applied, eventually falling off the screen.

What I’m wondering is if I can fix the position of the ship to the middle of the screen and have the world move instead ? When I say world, I mean platforms, etc…

For example, think of the arcade game Asteroids, but the player’s ship is fixed in the middle and when he thrusts, only the Asteroid field moves?

Hi @dax trajero,

Do you want to ship to be firmly locked in the center? Or do you want there to be a slight buffer, i.e. when the ship reaches toward a certain “edge” of a central zone, it moves the theoretical camera? The first option is much easier than the second.

In either case, you’ll probably want to move the world as a display group… but since you can’t shift display groups independently and get proper collisions using physics, you’ll need to constantly update (via Runtime) the ship’s offset position based on how much the world has moved. For example, if the world moves (in a given game cycle) 10 pixels to the right and 5 pixels down, you’ll need to update the ship position 10 pixels left and 5 pixels up, to offset the world’s movement while keeping the ship in the same coordinate-related space for physics collisions to work as expected.

You may want to experiment with the “Perspective” code from the Code Exchange. I haven’t tried it myself, but many users seem to vouch for it being useful and easy to implement.

http://developer.coronalabs.com/code/perspective

Take care,

Brent

You Sir, are a star!

I was thinking the same thing -  take the x,y deltas and use these to move the landscape around and put the ship back in the centre

To answer your question fully, I will allow a bit of easing, once I’ve implemented the fixed position method, so the ship does actually move around a bit as well.

Thanks again

UPDATE:

Checked the link you kindly gave me and BINGO! Within one minute I had exactly what I was looking for!

Brent’s pretty much nailed it there, but if your after a working example of something similar we have a template in our shop that moves the world around the player and locks the position to a set area. The videos pretty terrible but it gives you the general idea of whats going on :) http://www.tandgapps.co.uk/shop/top-down-shooter-template/ 

Hi @dax trajero,

Do you want to ship to be firmly locked in the center? Or do you want there to be a slight buffer, i.e. when the ship reaches toward a certain “edge” of a central zone, it moves the theoretical camera? The first option is much easier than the second.

In either case, you’ll probably want to move the world as a display group… but since you can’t shift display groups independently and get proper collisions using physics, you’ll need to constantly update (via Runtime) the ship’s offset position based on how much the world has moved. For example, if the world moves (in a given game cycle) 10 pixels to the right and 5 pixels down, you’ll need to update the ship position 10 pixels left and 5 pixels up, to offset the world’s movement while keeping the ship in the same coordinate-related space for physics collisions to work as expected.

You may want to experiment with the “Perspective” code from the Code Exchange. I haven’t tried it myself, but many users seem to vouch for it being useful and easy to implement.

http://developer.coronalabs.com/code/perspective

Take care,

Brent

You Sir, are a star!

I was thinking the same thing -  take the x,y deltas and use these to move the landscape around and put the ship back in the centre

To answer your question fully, I will allow a bit of easing, once I’ve implemented the fixed position method, so the ship does actually move around a bit as well.

Thanks again

UPDATE:

Checked the link you kindly gave me and BINGO! Within one minute I had exactly what I was looking for!

Brent’s pretty much nailed it there, but if your after a working example of something similar we have a template in our shop that moves the world around the player and locks the position to a set area. The videos pretty terrible but it gives you the general idea of whats going on :) http://www.tandgapps.co.uk/shop/top-down-shooter-template/