if ${Pawn[id,${ObjectID}].Distance} > ${MaxDist}
{
; *** add the following 2 lines
do
{
; ***
; echo Too far closing
; press and hold the forward button
VG:ExecBinding[movebackward,release]
VG:ExecBinding[moveforward]
; **** add a copy of the collision code
Face ${Pawn[id,${ObjectID}].X} ${Pawn[id,${ObjectID}].Y}
wait 5
; Check to make sure we have moved if not then try and avoid the
; obstacle thats in our path
if ${Math.Distance[${Me.X},${Me.Y},${Me.Z},${SavX},${SavY},${SavZ}]} < 1
{
; I think i might be stuck so save off the current time
if !${StuckCheck}
{
echo I might be stuck
StuckCheck:Set[TRUE]
StuckCheckTime:Set[${LavishScript.RunningTime}]
}
else
{
; If I am still stuck after 8 seconds then try and avoid the obstacle.
if ${Math.Calc[${LavishScript.RunningTime} - ${StuckCheckTime}]} > 8000
{
;echo Yep I am stuck trying to free myself
;call Obstacle
StuckCheck:Set[FALSE]
if ${VG.CheckCollision[${Pawn[id,${ObjectID}].X},${Pawn[id,${ObjectID}].Y},${Pawn[id,${ObjectID}].Z}](exists)}
{
call AvoidCollision ${Pawn[id,${ObjectID}].X} ${Pawn[id,${ObjectID}].Y} ${Pawn[id,${ObjectID}].Z}
if !${Return}
return "COLLISION"
}
}
}
}
; If I have moved away from my saved spot reset my stuck toggle
if ${StuckCheck}&&${Math.Distance[${Me.X},${Me.Y},${Me.Z},${SavX},${SavY},${SavZ}]} > 3
{
;echo I am no longer stuck
StuckCheck:Set[FALSE]
}
; **** finish copy of collision code
; *** Close the Do Loop with the following 2 lines
}
while ${Pawn[id,${ObjectID}].Distance} > ${MaxDist}
}