I believe that F50's solution was made before some of the new vector functions in 99c.
sysVectorAngle is the new one in 0.99

Code: Select all
<Gravity>
(enum (sysFindObject gSource "sN:200") target
(block (target distance playerPos targetPos bestDist bestDegree)
(setq distance (objGetDistance target gSource))
(setq playerPos (objGetPos gSource))
(setq targetPos (objGetPos target))
(setq bestDist 100000)
(setq bestDegree 0)
(setq angle (sysVectorAngle
(sysVectorSubtract
targetPos
playerPos
)
)
)
(setq vector2 (sysVectorPolarOffset Nil angle 10))
(objIncVel target (sysVectorDivide vector2 (add(distance) 1)))
)
)
</Gravity>
Code: Select all
(enum (sysFindObject gSource "sN:200") target
(block (target distance...)
...
Is that intended, or is this a bug?george moromisato wrote: And, unfortunately:
(add Nil 1) -> Nil
Try cleaning it up a little, then maybe it becomes more apparent. Put in a few dbgLogs to see where the error could be. When you have expressions being evaluated inside expressions, sometimes their errors don't really make it out. Make sure that you are not defining and using global variables by mistake (ie, make sure all local variables are defined in the (block (.....)) part).schilcote wrote: Gah, still won't work, the vectorDivide is dividing by 0. I'm pretty sure it's impossible for distance to be 0, because I'm adding one to it, so it must be the vector.
Code: Select all
<Gravity>
(block (ships)
(setq ships (sysFindObjects "sN:200"))
(dbgLog "Ships found: " ships)
(enum ships target
(block (distance targetPos playerPos angle direction push)
;; who is the target
(dbgLog "Target: " (objGetName target 1))
;; are you sure you dont wan't gPlayerShip?
(setq distance (objGetDistance target gSource))
;; is a sane distance actually found?
(dbgLog "Distance: " distance)
(setq playerPos (objGetPos gSource))
(setq targetPos (objGetPos target))
(setq angle (sysVectorAngle
(sysVectorSubtract
targetPos
playerPos
)
))
;; what is the angle found?
(dbgLog "Angle: " angle)
;; find the direction we want to push that target in
;; this will be relative to System Origin
(setq direction (sysVectorPolarOffset Nil angle 10))
;; lets print it, just for fun
(dbgLog "Direction Vector: " direction)
;; and lets find the force we want to push with
(setq push (sysVectorDivide
direction
(add distance 1)
))
;; and print it
(dbgLog "Push Vector: " push)
;; finally we do the actual push
(objIncVel target push)
)
)
)
</Gravity>
As we say in the business, it's working as coded.Wolfy wrote:Is that intended, or is this a bug?george moromisato wrote: And, unfortunately:
(add Nil 1) -> Nil
So he'd have to not define it in the block, or re-define it as zero, then calculate?