Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / distance formula problem, help

Author
Message
Daniel wright 2311
User Banned
Posted: 1st Apr 2011 00:30
ok, so Im using a function to see how far away I am from my enemies, then if they are so far away they follow me then attack,well, everything works fine until I walk away from them, they stop following me but there animations still walk and dont idle. So I need to figure out a way to check if I am far enough away for the animation to change back.Here is my code, any help is appreciated



my signature keeps being erased by a mod So this is my new signature.
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 1st Apr 2011 00:38
you could say:

I'm guessing nightanim=1 plays the walk animation?

Daniel wright 2311
User Banned
Posted: 1st Apr 2011 00:43
Yes you are right, ill try it and let you know, thank you

my signature keeps being erased by a mod So this is my new signature.
Daniel wright 2311
User Banned
Posted: 1st Apr 2011 00:48
No this did not work as the distance is diffrent but the same, so I changed it to 299 but still nothing, All they do now is they keep idling and they dont play there walk animation.

my signature keeps being erased by a mod So this is my new signature.
Cliff Mellangard 3DEGS
Developer
20
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 1st Apr 2011 00:58
You could try this distance function instead as its extremely fast and works the same in all angles!

before loop have this!

NULL= make vector3(5)


and then in the loop use this function to get the distance!

Function Dist(sourcex#,sourcez#,targx#,targz#)
Set Vector3 5,sourcex#-targx#,0,sourcez#-targz#
d#=Length Vector3(5)
Endfunction d#

i use this in the loop to get wath distance it is!
distance=Dist(PL_X,PL_y,Intersection.X,Intersection.Y)

Sorry iam tired
But hope it helps you somehow?

I belive its your weird distance stuff here?
(300 * 300)

How huge is your world ?
300*300 = 90 000
Daniel wright 2311
User Banned
Posted: 1st Apr 2011 01:08
@Cliff Mellangard 3DEGS

I tryed your code and Im not shure how to call for it here is how I am calling it and its not working right



my signature keeps being erased by a mod So this is my new signature.
Cliff Mellangard 3DEGS
Developer
20
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 1st Apr 2011 01:45
You must use this before your code!

distance = Dist(start X , start y , target X , target Y)

So that distance have an value!
Bacause now so does it have no value at all!
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 1st Apr 2011 01:46 Edited at: 1st Apr 2011 01:51
For what it's worth, if you did this..



It would make your comparisons a little more straight forward. x^0.5 is the same as sqrt(x), but seems to be faster. (or at least it used to be..)

Vector distance works too, but some time back there were tests to see which method took less time to execute, and the above function won out.

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 1st Apr 2011 02:25
Quote: "
How huge is your world ?"

he leaves the value squared. in 3d the "distance formula" is
(X1-X2)^2+(Y1-Y2)^2+(Z1-Z2)^2=D^2
so if you don't take the square root of the left side, you can just compared the distance squared.
You're saying "if D^2<300^2"
which is the same as "if D<300", it juts takes out a calculation.

KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 1st Apr 2011 03:29
Yeah, works out the same, just a little less confusing if you go ahead and sqrt the distance.

Login to post a reply

Server time is: 2026-07-11 14:56:24
Your offset time is: 2026-07-11 14:56:24