Forum Topic: Math Questions

(91 views • 6 replies)

This topic is 1 page long.

<< < > >>
None

UknownXL

Reply To Post Reply & Quote

Posted at: 11/3/09 08:05 PM

UknownXL EVIL LEVEL 10

Sign-Up: 05/22/05

Posts: 1,322

Ok so I found this code and I have been messing around with it a bit and I had a question. Basically im trying to get it so the enemy fallows the player mc.It works pretty good. but im not to sure why when _root.grounded == false; the enemy just starts walking in a straight line. Rather then just stopping. Can someone help me out?

Thanks
Matt V

onClipEvent (load) {
spd = 2;
}
onClipEvent (enterFrame) {
if (_root.grounded) {
Xdiff = _root.player._x-_x;
Ydiff = _root.player._y-_y;
radAngle = Math.atan2(Ydiff, Xdiff);
_rotation = int((radAngle*360/(2*Math.PI))+90);
updateAfterEvent();
}
if (_rotation>180) {
_y += (spd*Math.cos(Math.PI/180*_rotation));
_x -= (spd*Math.sin(Math.PI/180*_rotation));
} else {
_y -= (spd*Math.cos(Math.PI/180*_rotation));
_x += (spd*Math.sin(Math.PI/180*_rotation));
}
}


None

Fion

Reply To Post Reply & Quote

Posted at: 11/3/09 08:13 PM

Fion LIGHT LEVEL 34

Sign-Up: 08/21/05

Posts: 2,374

The actual movement code is outside of the if(_root.grounded){ block. So if you want him to stop moving when _root.grounded = false you either need to move the movement section inside the if statement or set the spd to zero when _root.grounded = false;


None

UknownXL

Reply To Post Reply & Quote

Posted at: 11/3/09 08:16 PM

UknownXL EVIL LEVEL 10

Sign-Up: 05/22/05

Posts: 1,322

Yea I just noticed that. I fixed it and it works now. Could someone explain sin cos and tan. I did this stuff in highschool but our teacher made us use a calculator for it so honestly I really never understood what was going on. I did ask once how to do it without one but he said it was impossible. Even though its obvious you cant.


None

Fion

Reply To Post Reply & Quote

Posted at: 11/3/09 08:20 PM

Fion LIGHT LEVEL 34

Sign-Up: 08/21/05

Posts: 2,374

If you picture a right angle triangle with one angle marked the sine of that angle is the ratio of the length of the side opposite that angle to the length of the hypotenuse(the longest side of the triangle, opposite the right angle). Cosine is similar expect that it is the ratio of the length of the adjacent side to the length of the hypotenuse. Tangent is the ratio of the opposite to the adjacent.


None

Fion

Reply To Post Reply & Quote

Posted at: 11/3/09 08:27 PM

Fion LIGHT LEVEL 34

Sign-Up: 08/21/05

Posts: 2,374

Picture to help. (bad quality)

Math Questions


None

UknownXL

Reply To Post Reply & Quote

Posted at: 11/4/09 12:31 AM

UknownXL EVIL LEVEL 10

Sign-Up: 05/22/05

Posts: 1,322

Ah yes its coming back now. Sohcahtoa
Sin opp of hyp, cos adj over hyp and tan opp over adj


None

Toast

Reply To Post Reply & Quote

Posted at: 11/4/09 12:34 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,918

At 11/4/09 12:31 AM, UknownXL wrote: Ah yes its coming back now. Sohcahtoa

Haha seriously? In france we say "Cah-soh-toa", which phonetically translates to "Casse-toi" which means "get the fuck out"

Either way you shouldn't memorise that by phonetic. It should become obvious by intuition. These are really basic notions


All times are Eastern Standard Time (GMT -5) | Current Time: 07:25 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!