Page 1 of 1

I sock at algebra Help ;(

PostPosted: Sun Apr 10, 2011 2:04 pm
by amanuob
can anyone help me in making a formula that enables you to get the X & Y of a certain coordinates from your character, the
given are the angle and distance, like angle=20° and distance from my character is=5.5 .... Thanx

Re: I sock at algebra Help ;(

PostPosted: Sun Apr 10, 2011 5:12 pm
by jimmynewguy
I'm a little confused by how you ask your question, could you be a little more specific??

A code to get the angle from one coordinate to another would be this:
Code: Select all
direction(x,y,x2,y2);

where x,y are the X & Y values of an actor and X2 & Y2 are the values of another actor

it's nearly the same code to get the distance:
Code: Select all
distance(x,y,x2,y2);


So let's say you have the character named "player" and the enemy named "enemy". If you wanted the enemy to follow the player only when the player is within a certain radius of the enemy you could do this:
enemy->draw actor->script editor->
Code: Select all
if(distance(x,y,player.x,player.y)<250)
{
angle = direction(x,y,player.x,player.y);
directional_velocity = 3;
}
else
{
directional_velocity = 0;
}

This will cause the enemy to follow the player at 3 pixels a frame if the player is within 250 pixels of the enemy, or stop moving if he is not.

Hope this helps somewhat, and if not you can explain further what you need.

Re: I sock at algebra Help ;(

PostPosted: Mon Apr 11, 2011 12:07 am
by amanuob
sry for the confusion :oops: , this is what i mean XD....
Image
its easy to get X & Y of an angle of 90,0,180,360;
ie.
Code: Select all
|90°
|
|________0°
|
|
|270°

player X=5 and Y=10
like degrees=270° distance=5.5
the answer would be
X=5 and Y=15.5->15

thanx for the help.

Re: I sock at algebra Help ;(

PostPosted: Mon Apr 11, 2011 12:23 am
by skydereign
For that you can use cos and sin. The following code moves the actor to the xy position you are talking about (notice it is relative to itself).
Code: Select all
MoveTo("Event Actor", cos(degtorad(angle))*radius, -sin(degtorad(angle))*radius, 10, "Event Actor", "");


Now, if you just want to get the xy values, here is what it looks like.
Code: Select all
int X = cos(degtorad(angle))*radius;
int Y = -sin(degtorad(angle))*radius;


Note that angle can be replaced to be your own angle variable, and radius set to anything.

Re: I sock at algebra Help ;(

PostPosted: Mon Apr 11, 2011 1:29 am
by amanuob
thanx:D +1;