Floating Platform

Apr 22, 2011 at 12:14 PM

Hi There,

I'm trying to create a platform that isn't affected by gravity and that moves back and forth across the screen in a single axis. Any ideas or examples would be really helpful.


 

Apr 28, 2011 at 9:57 AM

Hi,

I think that if you set its mass (easiest in Blend) to 0, then it won't fall down due to gravity. On the other hand I'm not really sure what you're after... Do you want dropping things to bounce from this object and that it still stays on the same y-level? Do you want gravity at all (in my game,I don't use gravity at all, so everything bounces in all directions).

I'm also unclear of how you want this platform to navigate in the x-plane. It can be done via a timer or via arrow keys, mouse buttons, etc as input from the user.

Let us know if you need more help.

/Pettrer

Apr 28, 2011 at 2:27 PM

Hi Pettrer,

Thanks for you reply, in answer to your questions: Yes i want the platform to be unaffected by other physics objects. So i assume the IsStatic property needs to be selected so the object is unaffected by gravity. A slider joint at a fixed angle maybe?

I want it to move back and forth on a single axis at a constant speed that is started as soon as the level is started / page is loaded. I wasn't sure what sort of impulse or force this falls under, or how to achieve this.

Cheers,

 

Daniel

Apr 28, 2011 at 7:17 PM

Hi Daniel,

As I'm pretty new to this myself, I'm not the one to provide you with code (sorry!), but this is what I'd do:

1. Set the object as static 8as you did)
2. Don't mess with jonts, impulses etc, but in your game timer loop, set the x position  += 1 until you reach the x max, and then go the other way.

I find that one has to decide whn to use code and when to use Blend/design mode. This time, I should definitely move the object via code.

To find out how to do the timer and other game stuff not related to Physics Helper, look here: http://blogs.msdn.com/b/nikola/archive/2009/02/05/anatomy-of-a-silverlight-game-avoid-common-mistakes-when-building-silverlight-online-games.aspx

Good luck!

/Pettrer

May 8, 2011 at 1:55 AM

Thanks for getting back to me, i've had a crack at your suggestions. It's pretty much working but i think i'm missing something in terms of screen to world co-ordinate transforms.

The platform object is initially positioned on the canvas at Left 42, Top 173 but the world position is quite different to this. Is there a converter to flip between these? Also should i be worried about time in this, i'm just using the default time step for the game loop.

Here's what i have so far, might be useful to someone else:

 

        void _physicsController_TimerLoop(object source)
        {

            if (physicsController.PhysicsObjects.ContainsKey("platform"))
            {
                var platformSprite = physicsController.PhysicsObjects["platform"];

                var currentPosition = platformSprite.BodyObject.Position;

                if (_startPostion == Vector2.Zero)
                {
                    _startPostion = platformSprite.BodyObject.Position;
                }

                if (currentPosition.X > (_startPostion.X + 10))
                {
                    _platformIncrement = -.05f;
                }
                else if (currentPosition.X < (_startPostion.X))
                {
                    _platformIncrement = .05f;
                }


                currentPosition.X = currentPosition.X + _platformIncrement;
                platformSprite.BodyObject.Position = currentPosition;

            }

        }
 

May 8, 2011 at 6:16 PM
Edited May 8, 2011 at 6:17 PM

Hi,

 You can convert between the two coordinate systems using physicsController.WorldToScreen() and physicsController.ScreenToWorld(). I usually just use the Rendering timestep for any dynamic actions. I haven't tried it with Physics Helper, but you might be able to use a storyboard for your platform instead. This will make the timing and animation easier. However, as I say, I've never tried using a storyboard on a physics object so have no idea if it'll work or not.

May 9, 2011 at 8:48 AM
keyboardP wrote:

you might be able to use a storyboard for your platform instead. This will make the timing and animation easier. However, as I say, I've never tried using a storyboard on a physics object so have no idea if it'll work or not.


Really interesting idea! That's three minutes work in Blend. Should have thought about it myself...

/Pettrer