Sprite Behaviors - Seek Problem

BlitzMax Forums/BlitzMax Beginners Area/Sprite Behaviors - Seek Problem

technician(Posted 2007) [#1]
My trials and tribulations with the Scott Shaver's Sprite Behaviors module continue. I've been working on this game for quite some time, and was just beginning to polish one aspect of it up, when my AI decided to go amuck.

I'm using state based AI, based on the book the Sprite Behaviors module comes from. If the AI's health desire gets really high, I have it run the following state code:

Type SeekHealth Extends State
	
	Function Instance:SeekHealth()
		Local instance:SeekHealth = New SeekHealth
		Return instance
	EndFunction
	
	Function EnterState(obj:AI)
	
		obj.currentStateID = SeekHealthState
		
		Local goalHealth:HealthPickup
		
		Local tempVal:Double = 9999
		For Local tHealth:HealthPickUp = EachIn HealthPickUp.List
			If tHealth.Empty = False
				If tempVal > Distance(obj.myVehicle.X,obj.myVehicle.Y,tHealth.X,tHealth.Y)
					tempVal = Distance(obj.myVehicle.X,obj.myVehicle.Y,tHealth.X,tHealth.Y)
					goalHealth = New HealthPickUp
					goalHealth = tHealth
				EndIf
			EndIf
		Next
		
		   obj.myVehicle.mySprite.GetSteering().SeekOn(goalHealth.mySprite)
		
	EndFunction
	
	Function ExecuteState(obj:AI)
		
	EndFunction
	
	Function ExitState(obj:AI)
	
		obj.myVehicle.mySprite.GetSteering().SeekOff()

	
	EndFunction
	
EndType


This finds the nearest health object, and sets the seek behavior on, with the target being the health object's sprite, which is located at the correct position. Now, if the AI changes state relatively near to the health pickup, everything works according to plan:

[IMG]http://i78.photobucket.com/albums/j93/ickthoose/aiproblems2.png[/IMG]

However, if the AI is near, say, the bottom of the map, and enters the state, the following problem occurs:

[IMG]http://i78.photobucket.com/albums/j93/ickthoose/aiproblems1.png[/IMG]

The problem I'm experiencing here is I have absolutely no idea why this isn't working! It was working for over a month during development (I'm very new to AI, so things are slow), but just recently decided to stop working. I've compiled all of the examples to make sure I haven't fudged the module itself up by accident, but they all work as they should.

The AI sprites are created with the CreateForSteering option, with 1 for mass, 2 for top speed, 2.1 for force, and 1 for turn rate. Wall avoidance is always on.

My state basically runs as so:

- During the main update method for the AI, the current state has its Execute function called.
- Upon changing a state, the current state's exit function is called, then the state is changed, and the new state's enter function is called.

I've been poring over this for hours, trying to figure it out, but have finally had enough. I don't know why it suddenly decided not to work, since I haven't changed anything, so I'm going to the forums. The Wander behavior seems to work just fine, for the Wander state, but anything related to Seek or Arrive or any of those just seems to go spazzy. I'm also frustrated because it works in some situations, yet doesn't in others.

Any help would greatly be appreciated!! This is a pretty important aspect of the game, and it's been incredibly disheartening to have it suddenly and inexplicably crash on me. If more information is required, I can post the full source code + media. I'm not particularly interested in doing so, but I'm very interested in getting this done, so I'll do it (my code usually sucks anyways).

Thanks in advance,
tech


Scott Shaver(Posted 2007) [#2]
That sucks. Wish I had any idea what was causing the problem. At least someone is using the module. I would guess that one of your state changes is freaking things out. Can you back out everything for the state stuff and slow put it back in?

Sorry I know this doesn't really help.


Who was John Galt?(Posted 2007) [#3]
I don't know anything about Scott's module, but try initialising tempVal to an even bigger number, like 99999999 and see if it works.


sswift(Posted 2007) [#4]
What does the State type look like, and how do you give objects these states and/or trigger a state change for an object with this setup?