Closest Waypoint?

Blitz3D Forums/Blitz3D Beginners Area/Closest Waypoint?

Guy Fawkes(Posted 2011) [#1]
Hi all, how can I make it so that if the enemy is currently chasing my character or it gets too far from its point, it goes back to the waypoint it came from?

Here's my function so far:



Thanks! :)

Last edited 2011


stayne(Posted 2011) [#2]
Are you trying to make another WoW? Text above the head, chasing the player, chat box, huge terrains, etc. Just seems like you are to me. Not a mean question I am just curious.


Guy Fawkes(Posted 2011) [#3]
Something better, and much more quality specific. HOWEVER, some of these functions I'm asking for are for my gothic game :)


Drak(Posted 2011) [#4]
This question had been answered before, and I believe I wrote this example for you earlier.

http://www.blitzbasic.com/Community/posts.php?topic=89386


Wings(Posted 2011) [#5]
Did you mean this ?

Select Mode

Case Mode=1
Guarding... looking for enemys around.. ahh a enemy, target ,set mode 2

Case Mode=2
Follow player, if close engouth bit it.
if player dies then mode=3
if player is to faraway then mode=3
if orginx,y is to faraway then mode=3
case mode=3
Walk to Orgin X,Y

Case mode=4
Playe dead..

End select


H&K(Posted 2011) [#6]
ok, I have this so far
Select Mode

Case Mode=1
Guarding... looking for enemys around.. ahh a enemy, target ,set mode 2

Case Mode=2
Follow player, if close engouth bit it. 
if player dies then mode=3
if player is to faraway then mode=3
if orginx,y is to faraway then mode=3
case mode=3
Walk to Orgin X,Y

Case mode=4
Playe dead..

End select
It doesnt work. Any Ideas


stayne(Posted 2011) [#7]
Typed this up, is some old simple AI code I wrote. Threw in some chasecam code in the archives. Hopefully this will give you some ideas.



Global gameFPS = 50

Graphics3D 1024,768,32,2
SetBuffer BackBuffer()

SeedRnd MilliSecs()

Global camera = CreateCamera ()
CameraZoom camera,1.6
CameraRange camera,.1,100000
CameraClsColor camera,50,50,50

Global player = CreateCube()
ScaleEntity player,4,10,4
PositionEntity player,0,10,-600

Global PlayerHP = 100

AmbientLight 150,150,150

light = CreateLight()
PositionEntity light,0,0,0

quit = False

framePeriod = 1000 / gameFPS
frameTime = MilliSecs () - framePeriod

redhome = CreateSphere()
ScaleEntity redhome,6,6,6
PositionEntity redhome,-400,10,0

Type CSys
	Field cx#, cy#, cz#
	Field mx#, my#, sps%
End Type

Type cube
	Field mesh
	Field walktimer
	Field turntimer
	Field moving
	Field decision
	Field distfromhome
	Field id
	Field team
	Field level
	Field strength
	Field stamina
	Field dmg
	Field dly
	Field hp
	Field home
	Field angry
	Field timer
	Field dice
	Field damage
	Field alive
End Type

For i = 1 To 10
	c.cube = New cube
	c\id = i
	c\team = 1
	c\hp = 100
	c\dmg = 8
	c\dly = 2000
	c\stamina = 18
	c\strength = 12
	c\level = 3
	c\alive = True
	c\home = redhome
	c\mesh = CreateCube()
	EntityColor c\mesh,255,0,0
	ScaleEntity c\mesh,4,4,4
	PositionEntity c\mesh,EntityX(c\home),EntityY(c\home),EntityZ(c\home)
	d.cube = c.cube
Next

Plane=CreatePlane()
EntityAlpha plane,.8
EntityColor plane,50,50,50
CreateMirror()

Repeat

	Repeat
		frameElapsed = MilliSecs () - frameTime
	Until frameElapsed

	frameTicks = frameElapsed / framePeriod

	frameTween# = Float (frameElapsed Mod framePeriod) / Float (framePeriod)

	For frameLimit = 1 To frameTicks

		If frameLimit = frameTicks Then CaptureWorld
		frameTime = frameTime + framePeriod
		
		ChaseCam(camera, player, 0, 4, -40, .1)
		
		If KeyHit(1) Then quit = True

		If KeyDown(17) Then MoveEntity player,0,0,4
		If KeyDown(31) Then MoveEntity player,0,0,-4
		If KeyDown(32) Then MoveEntity player,4,0,0
		If KeyDown(30) Then MoveEntity player,-4,0,0
				
		TurnEntity player,0,-MouseXSpeed()/2,0
		
		For c.cube = Each cube
	
			If c\alive = True

				If EntityDistance (c\mesh,player) < 500
					c\angry = True
					dy#=DeltaYaw(c\mesh,player)*.1
					TurnEntity c\mesh,0,dy,0
					
					If EntityDistance (c\mesh,player) > 300
						MoveEntity c\mesh,0,0,3
					EndIf
					
					If c\timer + c\dly < MilliSecs()
					
						c\dice = Rnd(1,5)
						c\damage = Ceil((c\strength * c\stamina * c\dmg) * c\dice * c\level / 10000)
						playerhp = playerhp - c\damage
						c\timer = MilliSecs()
						
					EndIf
					
					If c\hp <=0 Then c\alive = False
					
				Else
					c\angry = False
				EndIf
			
				c\distfromhome = EntityDistance(c\mesh,c\home)
					
				If c\angry = False
					
					If c\moving = False
						c\decision = Rand(1,200)
						Select True
							Case c\decision = 10
								c\walktimer = MilliSecs() + 3000
							Case c\decision = 100
								c\turntimer = MilliSecs() + 1000
						End Select
					EndIf
			
					If c\walktimer > MilliSecs() 
						c\moving = True
						MoveEntity c\mesh,0,0,3
					Else If c\turntimer > MilliSecs()
						c\moving = True
						TurnEntity c\mesh,0,2,0
					Else
						c\moving = False
					EndIf
			
					If c\distfromhome > 400
						dy#=DeltaYaw(c\mesh,c\home)*.04
						TurnEntity c\mesh,0,dy,0
					EndIf
				
				EndIf
			Else
				FreeEntity c\mesh
				Delete c
			EndIf
			
		Next

		UpdateWorld

	Next
	
	RenderWorld frameTween
	
	For c.cube = Each cube
		CameraProject(camera,EntityX(c\mesh),EntityY(c\mesh),EntityZ(c\mesh))
		
		Color 0,255,0
			
		Rect ProjectedX()-25,ProjectedY()-20,c\hp/2,4

	Next
	
	Text 10,10,PlayerHP
	
	Flip

Until quit = True

End

Function ChaseCam(cam, Entity, XOff#, YOff# = 2, ZOff# = -5, Spd# = 0.8)

	Local sys.csys = First csys
	Local nx#, ny#, nz#
	Local dx#, dy#, dz#
	Local ex#, ey#, ez#
	Local hit%
	
	If sys = Null 
		sys = New cSys
		sys\sps = CreatePivot()
	EndIf
	
	sys\mx = MouseX()
	sys\my = MouseY()
	sps = sys\sps
	PositionEntity sps, EntityX(entity), EntityY(entity), EntityZ(entity)
	TFormVector xOff, yOff, zOff, entity, 0
	ex# = EntityX(entity)
	ey# = EntityY(entity)
	ez# = EntityZ(entity)
	nx# = ex+TFormedX()
	ny# = ey+TFormedY()
	nz# = ez+TFormedZ()
	dx# = nx-ex
	dy# = ny-ey
	dz# = nz-ez
	hit = LinePick(ex, ey, ez, dx, dy, dz, 0.2)
	
	If hit
		nx = PickedX()
		ny = PickedY()
		nz = PickedZ()
	EndIf
	
	sys\cx = sys\cx+(nx-sys\cx)*spd
	sys\cy = sys\cy+(ny-sys\cy)*spd
	sys\cz = sys\cz+(nz-sys\cz)*Spd
	
	PositionEntity cam, sys\cx, sys\cy, sys\cz
	PointEntity Cam, Entity, 0

End Function



Graythe(Posted 2011) [#8]
That's MY code... well, it looks a bit like it but I was too embarrassed to post it here.


Graythe(Posted 2011) [#9]
@Rez, if you are having learning difficulty and you've not always been like that you need to see a doctor. I did - after I collapsed. I didn't like what I heard but it did very neatly explain a very great many things.


Ross C(Posted 2011) [#10]
I think Rez may be suspended?


Graythe(Posted 2011) [#11]
Censored

Last edited 2011


Graythe(Posted 2011) [#12]
Censored

Last edited 2011


Graythe(Posted 2011) [#13]
Censored

Last edited 2011


Graythe(Posted 2011) [#14]
I'm sure you understand... I meant no harm or insult...

Last point... Flameduck. Please send him my regards and apologies for all those years ago


Ross C(Posted 2011) [#15]
EDIT - ignore me then :)

Last edited 2011


Ginger Tea(Posted 2011) [#16]
I was/am puzzled by this too, but with it beeing the first yesterday and the forum does like screwing around then, perhaps the last comment was a multiple repost and nor harm or insult aimed at rez re the previous not edited post.