How to tell WHICH NPCs which point they belong to?

Blitz3D Forums/Blitz3D Beginners Area/How to tell WHICH NPCs which point they belong to?

Guy Fawkes(Posted 2011) [#1]
Hi all, as the title says, how do you make it, so that EACH different NPC knows which waypoint to go to?

How would I assign both the waypoints AND the NPCs the same IDs?

Thanks! :)


Matty(Posted 2011) [#2]
With a variable.

That's a very general question - where should one start?

Perhaps forget for now about the specifics of NPCs, waypoints, AI and such - and plan out a small program to get a rectangle to follow a set path in 2d space.

There are lots of ways of doing this. But explore the idea a little and have a go.


Guy Fawkes(Posted 2011) [#3]
I HATE 2d.


Matty(Posted 2011) [#4]
The same principles that apply to 'waypoint' in 2d apply in 3d. So perhaps try with a red cube navigating its way from blue cube to blue cube in 3d space then...


Guy Fawkes(Posted 2011) [#5]
Now THERE'S a good idea :)


Ginger Tea(Posted 2011) [#6]
but most NPC's follow a 2D route anyway, granted the terrain might raise or lower accordingly, but the route is rarely straight up (ala a ladder) just ground level and inclines.

So a 2D prototype is gonna be the foundations of a 2D in 3D one.


Guy Fawkes(Posted 2011) [#7]
i prefer 3d. the more complex it is, the easier it is for me to understand.


Ginger Tea(Posted 2011) [#8]
Well unless your characters and NPC's can fly or climb wall's most will be following a 2D route behind the scenes any way.
A 3D cube zooming along a flat plane along a predefined route or a line of sight is no different logically than a bitmap doing the same.

Chess is still chess if its played with paper pieces, a 2D notation heavy program, battle chess (great game) or fully rendered humans with fancy hats on a playing field*.

Hell I'd go as far as to say the multi layerd startrek chess game was nothing more than the same game with a fancy board, although I've never looked into it.

*One glastonbury (2000 I think) I along with others was trying to round up enough people to do LARP chess, most people said "but I don't know how to play chess."
To which I retorted "You don't have to, some one else is playing you would just be a playing piece.



Edit:
Unless you do need NPC's to traverse stairs and other floors in their route's, but I've found most just pootle about outdoors between huts waiting for you to engage them in conversation, ie staying in a 2D realm regarless of how hilly it might be.

Last edited 2011


Graythe(Posted 2011) [#9]
There are many ways to do it - here's a demo of one method

Const IntWidth%=4
Const EntityCount%=10
Const EntitySpeed#=.001

Global EntityIndex=CreateBank(IntWidth)
Global WaypointIndex=CreateBank(IntWidth)

Graphics3D 640,480,0,2
Light=CreateLight()
PositionEntity Light,0,0,-1
Camera=CreateCamera()

CreateEntities
CreateWayPoints	100




Repeat

	NoEntities=PeekInt(EntityIndex,0)
	For EntityLoop=True To NoEntities

		EntityBank=PeekInt(EntityIndex,EntityLoop*IntWidth)
		EntityNo=PeekInt(EntityBank,0)
		WaypointSerial=PeekInt(EntityBank,4)
		
		Select WayPointSerial
			Case False
				;No waypoint is selected! - Select a waypoint
				WayPointSerial=Rand(1,100)
				;Apply waypoint serial to entity
				PokeInt EntityBank,4,WayPointSerial
				;Set entity to yellow 
				EntityColor EntityNo,255,255,0
				
				Waypoint=PeekInt(WaypointIndex,WaypointSerial*IntWidth)
				;Point entity at new waypoint
				PointEntity EntityNo,Waypoint
				;Calculate moves required and store
				PokeInt EntityBank,8,EntityDistance(EntityNo,Waypoint)/EntitySpeed

			Default
				
				;How many moves Left?
				MovesCounter=PeekInt(EntityBank,8)
				If MovesCounter
					MoveEntity EntityNo,0.,0.,EntitySpeed
					PokeInt EntityBank,8,PeekInt(EntityBank,8)+-1
				Else
					;Waypoint reached - set waypoint to nil
					PokeInt EntityBank,4,False
					;Set entity to red
					EntityColor EntityNo,255,0,0
				End If

		End Select
									
	Next
		
	RenderWorld
	Flip

Until KeyHit(True)




Function CreateWayPoints(WayLimit%)

For WayLoop=True To WayLimit

	PointBank=CreateBank(16)
	Waypoint=CreatePivot()
	PositionEntity Waypoint,Rnd(-.5,.5),Rnd(-.5,.5),1.62+Rnd(-.5,.5)

	PokeFloat PointBank,0,EntityX(WayPoint)
	PokeFloat PointBank,4,EntityY(WayPoint)
	PokeFloat PointBank,8,EntityZ(WayPoint)

	PokeInt WaypointIndex,0,PeekInt(WaypointIndex,0)+True
	ResizeBank WaypointIndex,PeekInt(WaypointIndex,0)*IntWidth+IntWidth
	PokeInt WaypointIndex,PeekInt(WaypointIndex,0)*IntWidth,Waypoint
	
Next


End Function




Function CreateEntities()

;Create entities
For EntityLoop=True To EntityCount
	
	EntityBank=CreateBank(12)
	
	;Create, scale and position entity
	EntityNo=CreateCube()
	ScaleEntity EntityNo,.01,.01,.01
	PositionEntity EntityNo,Rnd(-.5,.5),Rnd(-.5,.5),1.62+Rnd(-.5,.5)

	;Increment entity count
	PokeInt EntityIndex,False,PeekInt(EntityIndex,False)+True
	;Adjust memory size
	ResizeBank EntityIndex,PeekInt(EntityIndex,False)*IntWidth+IntWidth
	;Append new entity to list
	PokeInt EntityIndex,EntityLoop*IntWidth,EntityBank

	;Store entity data
	PokeInt EntityBank,0,EntityNo
	;Select a waypoint serial at random
	PokeInt EntityBank,4,Rand(1,100)
	;Entity movement counter
	PokeInt EntityBank,8,False	

	EntityColor EntityNo,255,0,0
Next



Guy Fawkes(Posted 2011) [#10]
So this will figure out the closest waypoint if the NPC is chasing after a player?


Graythe(Posted 2011) [#11]
'How to tell WHICH NPCs which point they belong to?'.

That's what this demonstrates.


stayne(Posted 2011) [#12]
Naughty Alien answered your question in this thread dude...

http://blitzbasic.com/Community/posts.php?topic=89382#1015096