This project has moved. For the latest updates, please go here.

Getting forces to work?

Topics: User Forum
Feb 4, 2011 at 5:24 PM
Edited Feb 4, 2011 at 5:28 PM

So i'm just learning to use the engine, and i'm starting off with a simple helicopter with a thrust and is affected by gravity.

I've forgone the world gravity and opted to simply apply a force based on a mass value.

my code for applying the thrust is this


//creates thrust value based on thumbstick
player.thrust = -1000 * (padState.ThumbSticks.Left.Y+1);
//local variable to hold value of thrust based on rotation of helicopter
Vector2 force = new Vector2((float)(Math.Cos(DegToRad(player.rotation + 90)) * player.thrust), (float)(Math.Sin(DegToRad(player.rotation + 90)) * player.thrust));

//applies thrust force
copter.Body.ApplyForce(force, copter.Body.Position);
//applies gravity force
copter.Body.ApplyForce(new Vector2(0, player.mass*10), copter.Body.Position); //player mass is 100

//rotates helicopter


My problem is that it moves too slow. The forces don't seem to accumulate, theres no acceleration, the helicopter just moves at a seemingly constant speed. And I've tried increasing the forces but that just makes it move at a faster constant speed.

Constant force should create acceleration, so I must be doing something wrong. What should i do?

Feb 4, 2011 at 11:29 PM

You are probably not scaling your values to meters instead of pixels.

Feb 5, 2011 at 1:16 AM

How do i do that?

also, I don't know if thats it cause when I set the thrust ridiculously high (like 1000000) it just moves at a faster constant speed rather than accelerating.

Feb 5, 2011 at 1:05 PM

It is probably the most asked question on the forums, so instead of repeating myself, I would recommend you search the forums.

The samples also show you how to scale the world using a Camera2D class.

Feb 7, 2011 at 5:55 PM

So I found the Camera2D class in the DemoBaseXNA sample project. I've got all the files in my project but i'm not quite sure how to do the actual scaling. Is it using the function Camera2D.ConvertScreenToworld()? I'm guna try and figure it out but if someone could give me a brief explanation about how Camera2D and the pixels-meters idea works i'd appreciate it because I can't find an explanation in the forums.

Feb 7, 2011 at 7:05 PM

Search for "MKS" and you find dozens of threads. Also have a look at the HelloWorldXNA sample in source control (the new updated version). For starters use the Convert.XY(...) functions from DemoBaseXNA instead of Camera2D.

Feb 8, 2011 at 12:31 AM

I figured it out, thanks for the help guys!