5 Replies Latest reply on Mar 24, 2010 1:17 PM by kglad

# can somebody explain me this code pls!

speed *= .98;
x = Math.sin(_rotation*(Math.PI/180))*speed*-1;
y = Math.cos(_rotation*(Math.PI/180))*speed*-1;
if (!_root.granica.hitTest(_x+x, _y+y, true)) {
_x += x;
_y += y;
} else {
speed *= -.6;
}

root granica is an instance name i used, it can be anything else...

i believe shat speed is a variable or sth, cus i already used it earlier in the code and i guess now im just defining it...

but can somebody pleasee help me out by explaining what part of the code means what...

btw i also think that it has something to do with trigonometric functions, that sin and cos...

• ###### 1. Re: can somebody explain me this code pls!

that looks like code that should be attached to an object's enterframe loop.  it would cause the object to move along the axis of its rotation with easing.  if it hits _root.granica, the object will rebound at a slower speed.

• ###### 2. Re: can somebody explain me this code pls!

yeah man, youre right, it makes the car move, and bounce of from granica (granica - boundary in serbian)... good thinking...

but u did't understand what i asked, my question was that somebody explains me what does whicn part of the code do, like what does math.con mean or what ever, sth like that, i need somebody to explain me how the code works...

• ###### 3. Re: can somebody explain me this code pls!

speed *= .98; // decreases the speed - ie, will cause this object to gradually slow
x = Math.sin(_rotation*(Math.PI/180))*speed*-1; // these two lines cause the object to move in the direction of _rotation, the object's rotation
y = Math.cos(_rotation*(Math.PI/180))*speed*-1;
if (!_root.granica.hitTest(_x+x, _y+y, true)) { // this checks for no impending collision with _root.granica
_x += x;  // if there's no collision that would occur, advance to this position
_y += y;
} else {
speed *= -.6; // if there is an impending collision, don't move on this loop, reverse direction with a lower speed
}

• ###### 4. Re: can somebody explain me this code pls!

tnx a LOT man... you saved my life...

• ###### 5. Re: can somebody explain me this code pls!

you're welcome.