开发者

circular movement: simple math algorithm

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

circular movement: simple math algorithm

开发者_开发百科

I thin it is cos and sin related ! regards


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


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜