How to apply force in a direction

Jun 11, 2011 at 1:22 AM

Hi,

Let says I have a start point of 20,300 and end point of 100,280. I would like to apply force proportionally in the x and y directions.

Given the above coordinates force should be more in x direction than y direction.

Thanks

Jun 11, 2011 at 11:42 AM

Not exactly sure what you're trying to achieve, are you trying to move an object from point A to point B? If that's the case maybe just set the position manually in the timer loop.

If you just want to apply a force in that direction, i think your second point - the first should give you a vector in that direction that you use in the ApplyForce method.

Jun 11, 2011 at 12:52 PM

Hi,

Here is the basic Idea. Point1(20,300) is my reference point. I move the mouse around and click  somewhere on the screen (2nd point).

I want my object that is placed at  point1 to go in the direction of point2.

Thanks

Jun 12, 2011 at 9:15 AM

Ok, then you want the Point2 position - point1 to get your vector in the direction you want.

Then apply a force to the object you want to move in that direction.

var moveVector = Vector2.Subtract(new Vector(Point2.X,Point2.Y), new Vector(Point1.X,Point1.Y));

youPhysicsObjectYouWantToMove.BodyObject.ApplyForce(moveVector);

 

Jun 12, 2011 at 2:19 PM

Spruce, Thanks again for you help.

Jul 16, 2011 at 8:20 PM

How do you make an ellipse do this? I created an ellipse and named it "testEllipse" and dragged the PhysicsObjectBehavior onto it. So I want to move it point a to point b when an event is triggered. The problem is when it gets to the PhysicsSprite line it says it can't find "testEllipse" key. How do find the physics object?

PhysicsSprite temp = physicsController.PhysicsObjects["testEllipse"] as PhysicsSprite;

temp.BodyObject.ApplyForce(new Vector2(new Vector(Point2.X,Point2.Y), new Vector(Point1.X,Point1.Y)));