|
Development Forum |
 |
|  Sanely Insane
RisenAngel
     Manager

|
2/4/2014 | |
Most of my critters either swim or fly. I suppose that's not necessarily a bad thing (never can have enough fish), but at some point I'd like to code more walking critters.
However, the problem with walking critters is that they tend to get caught up on slopes. The "obst" command doesn't seem to be able to tell the difference between a wall and a slope, with the result that walking critters that rely solely on it tend to get "stuck" between two high areas (see the lesser trilobites in Past Seas and the lepts in Primordia).
I did manage a primitive sort of slope detection with the Past Seas greater trilobite; however, it was essentially "see if I can jump over this obstacle," which meant that they tried to jump over walls too.
I'd like to know the most efficient way to make a critter recognize climbable slopes while still turning around upon coming across a wall.
~ The Realm ~
Risen Angel's Creatures Blog
|

Moe
  

|
2/4/2014 | |
The crabs in C2toDS are slope sensitive. They will not walk off ledges and I think they won't attempt to climb insurmountable slopes either. Give their source a look? |

Malkin
     Manager

|
4/17/2014 | |
Just for reference's sake:
Finding the slope is part of the walk subroutine for the Crabs:
subr walk
setv ov09 room ownr
*if I'm going right, check my posr+wdth
doif ov14 eq 0
setv va21 posr
addv va21 15
setv va20 grap va21 post
elif ov14 eq 1
*if I'm going left, check my posl-wdth
setv va21 posl
subv va21 15
setv va20 grap va21 post
*dbg: outv va20
endi
doif ov09 ne grap va21 posy
*in case you're didn't check a room in time, and it's super steep
*and you can't find coords 15 pixels out because the room ends
*you should check the room you're in!
doif va20 eq -1
setv va20 room ownr
endi
gsub findslope
endi
sets va05 "Moves Left: "
adds va05 vtos ov15
*dbg: outs va05
doif ov15 le 0
gsub pickdirection
endi
doif ov14 eq 0
gsub goright
*dbg: outs "Right"
elif ov14 eq 1
gsub goleft
*dbg: outs "Left"
endi
retn
|
Finding the slope:
subr findslope
inst
doif va20 ne -1
gsub runthenumbers
endi
*Screw the angles, let's try finding the slope.
*subtract the floor's two y's to get the rise
subv va06 va05
absv va06
**dbg: outv va06
*subtract the room's two x's to get the run
subv va01 va02
absv va01
**dbg: outv va01
*divide the rise over the run, as floats
setv va01 itof va01
setv va06 itof va06
doif va01 ne 0.0000000
divv va06 va01
*dbg: outs "Slope:"
*dbg: outv va06
endi
*What if the room we've found has no floor, or it's floor is way low...
*Loop down and if there's another room, compare the door perm between them
setv va30 post
loop
addv va30 1
untl grap va21 va30 eq -1 or grap va21 va30 ne va20
**dbg: outv door grap va21 va30 va20
doif grap va21 va30 ne -1
doif door grap va21 va30 va20 gt perm
*If the floor is going to give way, you need to change directions
setv ov12 1
else
setv ov12 0
endi
endi
doif ov14 eq 1
doif va06 gt .6 or ov12 eq 1
setv ov14 0
setv ov15 rand 5 15
addv velx ov06
subv vely accg
*dbg: outs "Left was too steep"
endi
elif ov14 eq 0
doif va06 gt .6 or ov12 eq 1
setv ov14 1
setv ov15 rand 5 15
subv velx ov06
subv vely accg
*dbg: outs "Right was too steep"
endi
endi
slow
retn
|
And now to run the numbers...
subr runthenumbers
inst
setv va00 va20
sets va12 rloc va00
adds va12 " "
*number of loops, this is to determine what each variable means
setv va00 0
loop
inst
addv va00 1
*For the first loop, this is the 1 xLeft,
*second is 2 XRight, etc etc:: 3 LeftTop, 4 RightTop, 5 LeftFloor, 6 RightFloor
setv va16 stoi va12
*save the coords depending on the run.
doif va00 eq 1
setv va01 va16
elif va00 eq 2
setv va02 va16
elif va00 eq 3
setv va03 va16
elif va00 eq 4
setv va04 va16
elif va00 eq 5
setv va05 va16
elif va00 eq 6
setv va06 va16
endi
*this should delete just the " "
setv va13 sins va12 1 " "
setv va14 strl va12
subv va14 va13
addv va13 1
sets va12 subs va12 va13 va14
*Repeat
untl sins va12 1 " " eq -1
retn
endm |
I hope this helps! 
My TCR Norns |
|