Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
2 registered members (Grant, AndrewAMD), 911 guests, and 9 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
logic error? #176601
01/05/08 09:13
01/05/08 09:13
Joined: Aug 2004
Posts: 1,305
New York
PrenceOfDarkness Offline OP
Serious User
PrenceOfDarkness  Offline OP
Serious User

Joined: Aug 2004
Posts: 1,305
New York
hey guys.. i'm trying to make an entity get as close as possible to another entity without passing it, so i wrote this little script, but the moving entity just walks right past the stationary entity. I have no idea why... it's a logic error on my part, maybe someone knows why?

Code:

var destination[3];
var temp[3];
var OldDestDist[3]

if(destination[0] !=0)
{
temp = abs(vec_dist(my.x,destination));
if(temp < oldDestDist)
{
vec_set(oldDestDist,abs(vec_dist(my.x,destination)));
my.move = 1;
}
else
{
my.move = 0;
destination[0] = 0;
}
}



I don't think I need the abs(); but it was the same way either way so... any ideas people?

Last edited by PrenceOfDarkness; 01/05/08 09:14.

"There is no problem that can't be solved with time and determination." -me
prenceofdarkness for instant messages on AIM.

Looking for a model designer
PLEASE, SEND ME A PRIVATE MESSAGE OR EMAIL IF YOU'RE INTERESTED.
Re: logic error? [Re: PrenceOfDarkness] #176602
01/05/08 16:11
01/05/08 16:11
Joined: Oct 2002
Posts: 799
Germany->Bavaria->Nuremberg
C
Christian__A Offline
User
Christian__A  Offline
User
C

Joined: Oct 2002
Posts: 799
Germany->Bavaria->Nuremberg
Try to do something like this:

var distance_to_target;
var max_move_speed = 10;
var move_distance;

distance_to_target = vec_dist(my.x,target.x);

if ( distance_to_target < max_move_speed )
move_distance = distance_to_target;
else
move_distance = max_move_speed;

If you now move your entity the distance of move_distance in the direction to target, it exactly stops at the position of target


MfG, Christian__A. Visit my Site: www.chris-a.de


Re: logic error? [Re: PrenceOfDarkness] #176603
01/06/08 01:08
01/06/08 01:08
Joined: Dec 2006
Posts: 78
Nevada, USA
Futurulus Offline
Junior Member
Futurulus  Offline
Junior Member

Joined: Dec 2006
Posts: 78
Nevada, USA
I don't quite understand how your vectors are working. This line in particular
Code:
				vec_set(oldDestDist,abs(vec_dist(my.x,destination)));


should be an error. abs() will give you a number, the distance to the target, but then you're plugging that into vec_set. This will do something like
Code:
vec_set(oldDestDist, 50.000);

which would usually be a crash unless the distance happens to be a valid pointer.

You're also assigning a single number to an array in a few other places, although in C-Script this is valid as long as you realize you're assigning to the first element of the array only.

It seems like you need to make your var[3]s just vars.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1