3d adventure, interacting with objects, types,

Blitz3D Forums/Blitz3D Beginners Area/3d adventure, interacting with objects, types,

I'm currently trying to figure out a smart way to let the player interact with the 3d world's objects. These objects would probably be stuff like say, containers, lights, npcs. The idea is that the player can use these objects, pick them up, talk to them or combine other objects(from the inventory) with them. Normal adventure game stuff, but I'm not sure how should I aproach this.

Currebtly I'm using mouse to pick them, but I don't know how to "tell" the object what I want it to do. Maybe I need to add this type a field, which tells it what the player is after and how to react, but how would I access that, since It seems I'm actually picking just the mesh of this object?

Well once you picked an entity, you could access to a type item associated with it.

For example, you could create your entities and store the entity # in a type structure; later, when you pick an entity, you can scan the type list until you find the one picked.

my_new_entity = createcube() ;create a new entity
list = new t_list ;and a new type element which stores info
list\entity = my_new_entity ;assign to the field entity the entity#

;later: scan the entity list
picked = entitypick(.....)
if picked then
   for list.t_list = each t_list
      if list\entity = picked then
        ;read the entity info here
        exit
      endif
   next
endif



Hope it has sense for you,
Sergio.

This should give you a starting point. I would store the type handle in the entityname and the type instance can be easily retreived using the Object command ...

Note that by using STR$() to display the type instance you can see all the associated field values.

Hope this helps.

Graphics3D 640,480,16,1

Global Camera = CreateCamera()
PositionEntity Camera,0,50,0
RotateEntity Camera,90,0,0

Global Highlight = CreateCube()
ScaleEntity Highlight, 2, 2, 2
EntityAlpha Highlight,.5
HideEntity Highlight

Const ID_NPC = 1
Const ID_Light = 2
Const ID_Container = 3

Global CURRENT.GameObject	;selected object

Type GameObject
	Field Name$
	Field Entity
	Field ID
	Field Otherstuff
End Type

;set up some objects
For l = 1 To 20
	test.GameObject = GAMEOBJECTcreate( Rand(1,3) , Rand(-50,50), 0 , Rand(-50,50 ) )
Next

While Not KeyDown(1)

	GAMEOBJECTpick()
	RenderWorld()
	DISPLAY()
	Flip

Wend

;=================================================
;=================================================
;=================================================

Function DISPLAY()

	Color 255,255,255
	Oval MouseX()-5,MouseY()-5,11,11,0
	
	Text 0,0,"Selected Object : "
	If CURRENT<>Null 
		Text 0,20,Str$(CURRENT) 
	Else
		Text 0,20,"Nothing"
	End If
		
End Function

;=================================================
;=================================================
;=================================================

Function GAMEOBJECTpick()

	MR = MouseDown(1)
	ML = MouseDown(2)
	If MR Or ML
		CameraPick( Camera , MouseX(), MouseY() )
		GAMEOBJECTinteract( PickedEntity() )
	End If
	
End Function

;=================================================
;=================================================
;=================================================

Function GAMEOBJECTcreate.GameObject( ID , x#, y#, z# )

	g.GameObject = New GameObject
	g\ID = ID
	Select g\ID
		Case ID_NPC
			g\Name = "Non Player Character"
			g\Entity = CreateCube()
			EntityColor g\Entity,200,100,100
		Case ID_Light
			g\Name = "Light"
			g\Entity = CreateCylinder()
			EntityColor g\Entity,100,200,100
		Case ID_Container
			g\Name = "Container"
			g\Entity = CreateSphere()
			EntityColor g\Entity,100,100,200
	End Select

	EntityPickMode g\Entity , 2
	PositionEntity g\Entity, x, y, z
	NameEntity g\Entity, Handle( g )
	
	Return g
	
End Function

;=================================================
;=================================================
;=================================================

Function GAMEOBJECTinteract( Picked )

	If Picked > 0
		ShowEntity Highlight
		PositionEntity Highlight, EntityX( picked ), EntityY( picked ), EntityZ( picked )
		CURRENT = Object.GameObject( EntityName( Picked ))
		Select CURRENT\ID
			Case ID_NPC
				;reaction
			Case ID_Light
				;reaction
			Case ID_Container
				;reaction
		End Select		
	Else
		HideEntity Highlight
		CURRENT = Null
	EndIf

End Function
	


Thanks guys! That looks very helpful indeed. I should be able to make some progress now.