Page 1 of 1

** Need help, please. **

PostPosted: Thu Dec 23, 2010 4:08 pm
by Camper1995
Hi all. I am making new game "engine" that will be realistic. It have real physics and so.

Question: I have a line make from 2 actors. (actor1 and actor2)
who dont know what I mean, here is the script:

Code: Select all
erase(0,0,0,1); //erase...
setpen(0,255,0,0,15); //pen color..

moveto(actor1.xscreen, actor1.yscreen); //draw line from actor1...
lineto(actor2.xscreen, actor2.yscreen); //..to actor2.. ;)


So, how to set distance between these 2 actors. I want it to be 200pixels. How to set it ?
For those who dont understand what I want.
scrn1.jpg
what ever are the positions or actor1 and actor 2...

scrn2.jpg
..the distance between them must be 200px!

scrn3.jpg
explanation

Please help me if you can.

Thanks :)

Re: ** Need help, please. **

PostPosted: Thu Dec 23, 2010 9:30 pm
by skydereign
Well, if you want the players to be always within 200 pixels of each other, they would always be within a given circle. It kind of depends on how you want to set their position, but here is an example.
Actor1 -> Draw Actor -> Script Editor
Code: Select all
double ang = degtorad(direction(x, y, Actor2.x, Actor2.y));
x= Actor2.x+cos(ang)*200;
y= Actor2.y-sin(ang)*200;

Re: ** Need help, please. **

PostPosted: Fri Dec 24, 2010 12:57 pm
by Camper1995
Yeah. Its setting the distance 200pixels. Thanks good. But I dont know why, the actor 1 apears first time UP and then DOWN the actor 2.

Hm. Well, its working but not good.

Is there way to make it like:

if(x<actor2.x+200) {make distance between them be 200px} or something like that.

Dont know. But thanks for helping me. Merry Christmas! ;)

Re: ** Need help, please. **

PostPosted: Sat Dec 25, 2010 3:09 am
by skydereign
If you want it to be just when the distance is greater than 200, than you can use an if. But, there was a typo in my above post. Here's what it should have been.
Code: Select all
double ang = degtorad(direction(x, y, Actor2.x, Actor2.y));
x= Actor2.x-cos(ang)*200;
y= Actor2.y+sin(ang)*200;


With the if statement included would be this.
Code: Select all
if(distance(x,y,Actor2.x,Actor2.y)>200)
{
    double ang = degtorad(direction(x, y, Actor2.x, Actor2.y));
    x= Actor2.x-cos(ang)*200;
    y= Actor2.y+sin(ang)*200;
}

Re: ** Need help, please. **

PostPosted: Sat Dec 25, 2010 12:15 pm
by Camper1995
WOW! Great work Skydereign! ;) You helped me again. Nice and thanks a lot. ;)

+1 :mrgreen: