lundi 9 janvier 2017

How to make my character move random using javascript

var dx:Number = 0;
var dy:Number = 0;
var target:Point;
var Speed: Number= 10;


target = new Point (Math.random() * 500,Math.random() * 400);

trace (target);

stage.addEventListener(Event.ENTER_FRAME,FollowBall);


function FollowBall(event:Event):void
{

var angle = Math.atan2(dy,dx) / Math.PI * 180;
Mozzie.rotation = angle;

dx=Mozzie.x - target.x;
dy=Mozzie.y - target.y;
Mozzie.x -= dx / Speed;
Mozzie.y -= dy / Speed;

var hyp = Math.sqrt((dx*dx)+(dy*dy));


if (hyp<=20)
{

target.x = Math.random() * 1000;
target.y = Math.random() * 600;

}

}

Previously i am using actionscript 3.0 to do my animation but now i have to convert my code to javascript. And i know nothing about javascript, i need some help here.

Aucun commentaire:

Enregistrer un commentaire