creatures caves welcome, guest
downloads   gallery   dev   community   creatchi   forum   mycaves
bookmarks | search | post new topic
Development Forum
old
Determining Distance Between Two Objects   
RisenAngel
Sanely Insane

RisenAngel
United States  
Manager


 visit RisenAngel's website: The Realm
  12/10/2013

I'm currently trying to code a plant whose color varies depending on how close it is to another object.

There's four color variations, but so far I can get only two to show up: the color that shows up when the plant touches the other object, and the color that shows up when the plant is right next to the other object. The other two colors will not show up unless I start using decimal values.

The code that actually determines distance:
*Determine vent distance - this determines the color of the worm
subr vent
setv va99 0
*Are you touching a vent?
ttar 1 1 18833
doif targ <> null
setv va99 1
endi

targ ownr
*If you are, make that your color
doif va99 = 1
setv ov02 0
else
*Set default distance
setv va01 posx
setv va02 100
*Cycle through surrounding vents
esee 1 1 18833
*Get vent position
setv va10 relx targ ownr
*Make sure it's an absolute value
doif va10 < 0
negv va10
endi

*Is it less than than the current value?
doif va10 < va02
*If so, make it the new value
setv va02 va10
endi
next
targ ownr
*Worm color depends on the closest vent
setv ov02 va02
endi
retn


And the code that determines color:
*If really close to a vent, be red
doif ov02 = 0
setv va50 4
setv va51 5
setv va52 6
*If close to a vent, be mostly orange
elif ov02 > 0 and ov10 < 25
setv va50 7
setv va51 8
setv va52 9
*If far from a vent, be green and purple
elif ov02 >= 25 and ov10 < 50
setv va50 10
setv va51 11
setv va52 12
*If really far from a vent, be blue
elif ov02 >= 50
setv va50 13
setv va51 14
setv va52 15
endi


Is this the best way (or even a working way) to go about doing this? If so, what am I doing wrong? If not, what am I supposed to do?


~ The Realm ~
Risen Angel's Creatures Blog


 
Moe

Moe


 visit Moe's website: Creatures 2 to Docking Station
  12/10/2013

I am terrible at reading other people's codes, but this should do what you're looking for.

It's an example cos file and sprite that changes it's pose based on it's proximity to trapper plants. You can theoretically modify the code to apply to your agent.

Range 500
4 Levels:
Touching trapper
Less than 250px from trapper
More than 250px from trapper but still visible
and, no trapper in sight.

 
Papriko
Peppery One

Papriko



  12/11/2013  1

Moe's code only checks for the X-distance (RELX command), but when you want to check in an actual round radius in all directions, try DISQ instead:

The CAOS Documentation wrote:
DISQ (float) other (agent)
Returns the square of the distance between the centre points of the target agent, and the other agent. It is quicker to compare this square against a squared constant directly, or if you need the actual distance use SQRT.



As it points out, it checks for squared values, instead of normal ones, such as values of 500 for example, you had to check for 250000.


Lets play plants! Photosynthesis... Photosynthesis... Photosynthesis...
 


downloads
cobs
adoptions
creaturelink
metarooms
breeds
 
gallery
art
wallpaper
screenshots
graphics
promos
sprites
dev
hack shack
script reservations
dev resources
active projects
dev forum
 
community
links
advice
chat
polls
resources
creatchi
 
forum
bookmarks
general
news
help
development
strangeo
survivor
mycaves
log in
register
lost pw
0 online
creatures caves is your #1 resource for the creatures artificial life game series: creatures, creatures 2, creatures 3, docking station, and the upcoming creatures family.

contact    help    privacy policy    terms & conditions    rules    donate    wiki