I sock at algebra Help ;(

Non-platform specific questions.

I sock at algebra Help ;(

Postby amanuob » Sun Apr 10, 2011 2:04 pm

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
Questions are necessary for the development of our own knowing, without questions How would we know??? and lesser would be my posts or none...therefore I know little or none.
User avatar
amanuob
 
Posts: 33
Joined: Sat Aug 29, 2009 11:47 am
Location: In Earth
Score: 1 Give a positive score

Re: I sock at algebra Help ;(

Postby jimmynewguy » Sun Apr 10, 2011 5:12 pm

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.
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: I sock at algebra Help ;(

Postby amanuob » Mon Apr 11, 2011 12:07 am

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.
Last edited by amanuob on Fri May 06, 2011 5:48 am, edited 4 times in total.
Questions are necessary for the development of our own knowing, without questions How would we know??? and lesser would be my posts or none...therefore I know little or none.
User avatar
amanuob
 
Posts: 33
Joined: Sat Aug 29, 2009 11:47 am
Location: In Earth
Score: 1 Give a positive score

Re: I sock at algebra Help ;(

Postby skydereign » Mon Apr 11, 2011 12:23 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: I sock at algebra Help ;(

Postby amanuob » Mon Apr 11, 2011 1:29 am

thanx:D +1;
Questions are necessary for the development of our own knowing, without questions How would we know??? and lesser would be my posts or none...therefore I know little or none.
User avatar
amanuob
 
Posts: 33
Joined: Sat Aug 29, 2009 11:47 am
Location: In Earth
Score: 1 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest