Quote:
Originally Posted by coreys
I only have the angles split into x and y because of checking if it's hitting a wall vertically or horizontally. That's the only way I could think of doing it.
|
This is probably why it's not functioning like you'd want it to. sin() and cos() already split an angle into y- and x-components. So, you only need a single angle.
Here is an example:
PHP Code:
//#CLIENTSIDE
function onCreated() {
this.img = showimg(2001,"block.png",40,40);
this.img.layer = 7;
this.img.angle = pi/8;
this.img.velocity = 8;
this.img.w = getimgwidth(this.img.image);
this.img.h = getimgheight(this.img.image);
onTimeout();
}
function onTimeout() {
with (this.img) {
for (temp.i=0; temp.i<this.velocity; temp.i++) {
if (abs(screenwidth/2-this.x-cos(this.angle)-this.w/2)<screenwidth/2-this.w/2)
this.x += cos(this.angle);
else
this.angle = pi-this.angle;
if (abs(screenheight/2-this.y+sin(this.angle)-this.h/2)<screenheight/2-this.h/2)
this.y -= sin(this.angle);
else
this.angle = -this.angle;
}
}
timeout = 0.05;
}