yarek
yarek

Reputation: 12064

circular movement: simple math algorithm

I have to calculate dx and dy so player1 has a circular movement.

enter image description here

I thin it is cos and sin related ! regards

Upvotes: 1

Views: 1156

Answers (2)

Tauf
Tauf

Reputation: 21

Well,

x=h+cos(angle) and y=k+sin(angle)

where h is the x-coordinate of the center and k is the y-coordinate of the center.

So if you want to know what dx and dy are, then just take the derivative of both of those equations with respect to t (d/dt).

Upvotes: 1

Bosworth99
Bosworth99

Reputation: 4244

This looks like homework. Here are some basic elements to get you started:

var angle:Number = 45;
var centerPoint:Point = new Point(100,100);
var radius:uint = 100;
var radian:Number = angle * (Math.PI / 180);
var x:Number = (centerPoint.x + radius) * Math.cos(radian);
var y:Number = (centerPoint.y + radius) * Math.sin(radian);

In this case, you would need to work the x and y variables into a function that gets called over time, where the angle variable increments towards an endpoint (your target).

Cheers

Upvotes: 1

Related Questions