** Need help, please. **

Non-platform specific questions.

** Need help, please. **

Postby Camper1995 » Thu Dec 23, 2010 4:08 pm

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 :)
Say hello to my little friend.
User avatar
Camper1995
 
Posts: 707
Joined: Tue Dec 30, 2008 7:20 pm
Location: Lost in the past.
Score: 44 Give a positive score

Re: ** Need help, please. **

Postby skydereign » Thu Dec 23, 2010 9:30 pm

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

Re: ** Need help, please. **

Postby Camper1995 » Fri Dec 24, 2010 12:57 pm

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! ;)
Say hello to my little friend.
User avatar
Camper1995
 
Posts: 707
Joined: Tue Dec 30, 2008 7:20 pm
Location: Lost in the past.
Score: 44 Give a positive score

Re: ** Need help, please. **

Postby skydereign » Sat Dec 25, 2010 3:09 am

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

Re: ** Need help, please. **

Postby Camper1995 » Sat Dec 25, 2010 12:15 pm

WOW! Great work Skydereign! ;) You helped me again. Nice and thanks a lot. ;)

+1 :mrgreen:
Say hello to my little friend.
User avatar
Camper1995
 
Posts: 707
Joined: Tue Dec 30, 2008 7:20 pm
Location: Lost in the past.
Score: 44 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest