Global and Collisions

Blitz3D Forums/Blitz3D Beginners Area/Global and Collisions

CodeOrc(Posted 2008) [#1]
Hi All,

Sorry if this has been answered but could not find it using search.

Is there a limit on globals and collision types you can use?

Or is it a "good idea" to stay within a certain limit ?

thx :)


Sledge(Posted 2008) [#2]
The collision type has to be between 0 and 999 inclusive.


GfK(Posted 2008) [#3]
'Collision types' are just integers, so I'd assume 16.7 million or whatever the upper limit for a 4-byte Int is. [edit] Sledge reckons its much lower so I'd test the theory.

I believe there's a limit of the number of Globals - I have a vague memory of someone mentioning it years ago but iirc, its stupidly, stupidly high.

I wouldn't worry about either, tbh. If you ARE worrying about hitting limits in either area, then there's probably a much more efficient way of doing whatever it is you're doing.


CodeOrc(Posted 2008) [#4]
ok, thank you. I have 30 globals and 25 collision settings for my game so I thought I'd check just to be safe.

thx again guys :)


Sledge(Posted 2008) [#5]
Sledge reckons its much lower so I'd test the theory.
I pulled those numbers straight out of the docs... so they may very well be wrong :P


Stevie G(Posted 2008) [#6]
You have 30 collision types?! I can't think of any reason why that would be necessary. What is it you're doing as all those collision groups could result in some major slowdown IIRC?


CodeOrc(Posted 2008) [#7]
StevieG, it's 25 coll types. The reason for that is I have over 20 types of collectables, and interactable objects.

AND, I have 15 diff types of monsters that require diff types of behaviors assigned to them.

Am I missing something ?


Stevie G(Posted 2008) [#8]
Yes. You probably should only have a couple - one for all the monsters and one for all the collactables. It really depends on how many different collision responses you have.

To determine whether you've collided with a specific kind of monster you could initially name the entities as their respective monster names.

i.e. NameEntity( BOG_BEAST_MESH , "BOG BEAST" )

Then refer to the entityname when collided to determine what you've collided with.


An alternative and IMO best method, assuming you're using types to store all the monsters information, is to store the type handle in the entities name ...

m.MonsterT = new MonsterT
m\Entity = copyentity( BOG_BEAST_MESH )
m\Name = "BOG BEAST"
m\Life = 1.0
m\Armour = .75
Nameentity( m\Entity , handle( m ) )


Then when you know the collided entity this will give you the specific monster ..

m.MonsterT = object.MonsterT( entityname( Entity ) )
m\Life = m\Life - .01


Stevie


CodeOrc(Posted 2008) [#9]
Stevie -I have managed to make a disaster of my code trying to implement your idea...I'm still fairly new at this.

I know this may be alot to ask, but could you make a fully functional example of your idea using like 10 spheres and 10 boxes as diff coll types so I can wrap my head around this. And make it so I can shoot them plz.

I'd greatly appreciate the help, hopefully this thread will help others as well.

thx for your help :)


Stevie G(Posted 2008) [#10]
Why not post the code you have ( making sure no external media is required ) and I'm sure I or other tell you where you're going wrong?

The method I described above is used in my old Tanx game .... the BULLETSupdate function is one to look at.

http://www.blitzbasic.com/codearcs/codearcs.php?code=1095


CodeOrc(Posted 2008) [#11]
Ok, here it is, thx for being willing to take a look.

Now, when I shoot at my badguys, it works kinda...meaning that when I kill one, only the first one loaded takes the damage, and respawns, but the one's I actually shoot are still there.

so it seems that a\entity loaded first takes all the damage from all the others.

;Load Actor(s)
SeedRnd MilliSecs()
For loop = 1 To 15
	a.actor = New actor
	a\entity  = CopyEntity( scifiguy )
	EntityType a\entity,TYPE_BADGUY
	EntityRadius a\entity,rsize#
	Animate a\entity,1,.5,1
	PositionEntity a\entity,Rnd(1,200),32,Rnd(1,290)
	ScaleEntity a\entity,.12,.12,.12
	Print loop
Next


;Shooting the badguy
If CountCollisions(b\sprite)>0 ;this is my bullet
	
	If EntityCollided(b\sprite,TYPE_BADGUY) ;collisions have been set via Const

	  For a.actor = Each actor
            If EntityDistance(b\sprite,a\entity)<9
			  enemy_hit_counter=enemy_hit_counter+1
			   EmitSound bad_guy_sound,a\entity
			   RotateEntity a\entity,0,270,0
		 	 If enemy_hit_counter=>1 
		 	  score=score+5115
			   PlaySound spawn_sound
			   kill_counter=kill_counter+1
		  	  HideEntity a\entity:TranslateEntity a\entity,0,-200,0:PositionEntity a\entity,80,-1,-88:ShowEntity a\entity
		 	  enemy_hit_counter=0
		 	 EndIf
		 	EndIf

	   Next
 EndIf
EndIf



Stevie G(Posted 2008) [#12]
This should work ...

;Load Actor(s)

SeedRnd MilliSecs()
For loop = 1 To 15
	a.actor = New actor
	a\entity  = CopyEntity( scifiguy )
	EntityType a\entity,TYPE_BADGUY
	EntityRadius a\entity,rsize#
	Animate a\entity,1,.5,1
	PositionEntity a\entity,Rnd(1,200),32,Rnd(1,290)
	ScaleEntity a\entity,.12,.12,.12
	
	;SG
	NameEntity a\Entity, Handle(a)
	;SG
	
	Print loop
Next

;Shooting the badguy
If CountCollisions(b\sprite)>0 ;this is my bullet

	;SG	
	Entity = EntityCollided(b\sprite,TYPE_BADGUY) ;collisions have been set via Const

	If Entity > 0

		a.actor = Object.actor( EntityName( Entity ) )
		If a <> Null
			enemy_hit_counter=enemy_hit_counter+1
			EmitSound bad_guy_sound,a\entity
			RotateEntity a\entity,0,270,0
			
			If enemy_hit_counter=>1 
				score=score+5115
				PlaySound spawn_sound
				kill_counter=kill_counter+1
				HideEntity a\entity
				TranslateEntity a\entity,0,-200,0
				PositionEntity a\entity,80,-1,-88
				ShowEntity a\entity
			 	enemy_hit_counter=0
			EndIf
			
		EndIf

	EndIf

EndIf



CodeOrc(Posted 2008) [#13]
THANK YOU!!!

Works just how I wanted it too. And your right...now I do not need so many coll types...this is going to save me a monstrous amount of time- not to mention game performance.

Oh, and your tank game is incredible, very nice work there !!

One other question if you don't mind...as you see I am loading 15 badguys...I can load 100, but peformance takes a big hit. Is there a "magic" number for doing the "For/Next 1 To XX" loop?


Gabriel(Posted 2008) [#14]
If you're not already doing so, consider using MD2's for the actors. They're considerably faster, particularly when working with very large numbers. ( 100 animated models is a lot! )


CodeOrc(Posted 2008) [#15]
I am using some .B3Ds I purchased from various website...some do come with md2 versions so I will give those a go.

And your right 100 is alot, I am actually using 15 per routine...but wanted to try 100 as a test :)


Gabriel(Posted 2008) [#16]
For the ones which don't come with MD2 versions, you may want to look at FragMotion from FragMosoft. I believe it's able to convert B3D to MD2, although that's only what I've been told.


CodeOrc(Posted 2008) [#17]
Gabriel, I dl'd FragMotion and it exported nicely, thank you for the heads up.

Odd though, now my bullets go through the badguys instead of registering a hit.

I did not change the code StevieG posted above with the exception of course LoadMD2 instead of the LoadAnimMesh and finally AnimateMd2.

I put back the Animate common command, and the common LoadAnimMesh command and all i swell again.

So the puzzling question is this, when using MD2 format do I need to do any "special" stuff for my coll/global/const orders?

I look in the help files under the MD2 section but could not find anything directly stating that...but then again this is the first time I've ever used the MD2 format.


CodeOrc(Posted 2008) [#18]
So....

Now I want to add a secondary monster that provides me with a higher score than the first type.

Using your code above Stevie, I have spent 4 days trying to figure out how to make it manage more than 1 monster type via a higher score for a secondary monster and can't get it to work.

Example;
Arena #1 has 3 monster, all with diff score given for killing it.

How do I mod the code above to reflect that ?

Sorry to ask, but I am all out of options and cannot figure it out.

thx for any help you can provide.


H. T. U.(Posted 2008) [#19]
Can't you just add another field for score? Add that value to the score instead of 5115 every time (it can be customized for each kind of monster).

By the way, on your original subject of collisions, there would be little reason (except for classification) to have more than 18 collision types since that would allow entities to detect and respond to collisions in all possible ways.

Stevie, thanks for that code with the object command (I've tried to use it frequently but failed since it's not in the docs). Now I feel like a type master >:)


CodeOrc(Posted 2008) [#20]
Ok, I think I got it !!

I am simply checking the handle range(s) that a group was loaded in...
If Handle(a) >0 ;as in the loop = 1 to 20
  If Handle(a) <21 ;as in the loop = 1 to 20
    ;give bad guys these values for bad guy style #1
 endif
endif

If Handle(a) >20 ;as in the loop = 21 to 40
  If Handle(a) <41 ;as in the loop = 21 to 40
    ;give bad guys these values for bad guy style #2
 endif
endif


It works like a charm...although there may be a smarter way to do it, but this seems to work without any performance issues.


Stevie G(Posted 2008) [#21]
There are loads of ways of doing this but I wouldn't recommend using the handle method above. As has been suggested, just add an 'ID' or 'Style' field + a 'points' field into the actor type and create some constants to refer to each ID. This will tell you what kind of monster that .actor is.

e.g.

;Load Actor(s)

SeedRnd MilliSecs()

Const ID_PLAYER = 0
Const ID_MONSTER1 = 1
Const ID_MONSTER2 = 2

Type actor
	Field ID
	Field Points
	Field Entity
End Type

ACTORcreate( ID_PLAYER )				;create 1 of player
ACTORcreate( ID_MONSTER1 , 20 , 5115 )	;create 20 of monster1
ACTORcreate( ID_MONSTER2 , 15 , 1000 ) 	;create 15 of monster2

;
;
;
;
;
;
;
;

;Shooting the badguy
If CountCollisions(b\sprite)>0 ;this is my bullet

	;SG	
	Entity = EntityCollided(b\sprite,TYPE_BADGUY) ;collisions have been set via Const

	If Entity > 0

		a.actor = Object.actor( EntityName( Entity ) )
		If a <> Null
			enemy_hit_counter=enemy_hit_counter+1
			EmitSound bad_guy_sound,a\entity
			RotateEntity a\entity,0,270,0
			
			If enemy_hit_counter => 1


				;SG
				score = score + a\Points
				
				;do stuff based on ID
				Select a\ID
					Case ID_PLAYER
					Case ID_MONSTER1
					Case ID_MONSTER2
				End Select
				
				;SG
						
				PlaySound spawn_sound
				kill_counter=kill_counter+1
				HideEntity a\entity
				TranslateEntity a\entity,0,-200,0
				PositionEntity a\entity,80,-1,-88
				ShowEntity a\entity
			 	enemy_hit_counter=0
			EndIf
			
		EndIf

	EndIf

EndIf

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

Function ACTORcreate( ID , Number = 1 , Points = 0 )

	For loop = 1 To Number
	
		a.actor = New actor
		a\entity  = CopyEntity( scifiguy )
		
		;SG
		a\ID = ID
		a\Points = Points
		;SG
		
		EntityType a\entity,TYPE_BADGUY
		EntityRadius a\entity,rsize#
		Animate a\entity,1,.5,1
		PositionEntity a\entity,Rnd(1,200),32,Rnd(1,290)
		ScaleEntity a\entity,.12,.12,.12
		NameEntity a\Entity, Handle(a)
		
	Next
	
End Function



CodeOrc(Posted 2008) [#22]
Um...I will give this a go and see if I can figure it out...


Thanks for your help, you are a very nice person.


CodeOrc(Posted 2008) [#23]
I want to use different meshes for the different monsters. It seems with the system above I am only able to use 1 mesh.

I could easily be missing something, I will study it further, but so far I have it in my game and working, but only with 1 mesh, as 2 different monster ID's.


Stevie G(Posted 2008) [#24]
Just add an extra parameter to the ACTORcreate function which tells you which MeshTemplate to copy. Like so...

Const ID_PLAYER = 0
Const ID_MONSTER1 = 1
Const ID_MONSTER2 = 2
Global skifiguy = LoadMesh( "Scifigui"): HideEntity skifiguy
Global Monster1 = LoadMesh( "Monster1") : HideEntity Monster1
Global Monster2 = LoadMesh( "Monster2") : HideEntity Monster2

ACTORcreate( ID_MONSTER1 , Monster1 , 10, 5550 )

;------------------------------------------------------------

Function ACTORcreate( ID , MeshTemplate , Number = 1 , Points = 0 )

	For loop = 1 To Number
	
		a.actor = New actor
		a\entity  = CopyEntity( MeshTemplate )
		
		;SG
		a\ID = ID
		a\Points = Points
		;SG
		
		EntityType a\entity,TYPE_BADGUY
		EntityRadius a\entity,rsize#
		Animate a\entity,1,.5,1
		PositionEntity a\entity,Rnd(1,200),32,Rnd(1,290)
		ScaleEntity a\entity,.12,.12,.12
		NameEntity a\Entity, Handle(a)
		
	Next
	
End Function


There are much neater ways of doing this but it'll give you a start.

Stevie


CodeOrc(Posted 2008) [#25]
ahh...I see, thanks again man.

<> EDIT <>

I managed to add Scale for my diff monster types also based on your code...woohoo...I am impressed at your willingness to help, and hopefully this helps more people than just myself.

THX StevieG !!


CodeOrc(Posted 2008) [#26]
I have a major problem, could be my design is too ambitious for B3D.

I have 7 Areas, all with 3 Monster Types each @ 5 monster per type = 21 Unique Monsters and 105 monsters in total.

I got them all to load, and behave where they are supposed to but wow- my framerate is like 5 FPS...ouch !!

No special anything is going on, just planes to simulate my areas, and then your code StevieG to load and check to see if I shoot them.

So are my numbers too intense for B3D ?


H. T. U.(Posted 2008) [#27]
What are your computer specs?


Gabriel(Posted 2008) [#28]
105 what? 105 cubes, each with 12 polys? 105 animated characters, each with 40 bones and 5,000 polys?


H. T. U.(Posted 2008) [#29]
That is a lot of stuff.


CodeOrc(Posted 2008) [#30]
@ H.T.U
Basic Specs are;
1 Gig Ram
Intel 2.6 CPU
Nvidia GeForce 7600 GS with 512 Video Memory DDR2

@ Gabriel
-My models are basically variations of the "SciFiGuy" (placeholder for time being) that was used in the "Plasma2004" project here in the forums. By variations, I mean texture differences, scale, etc, but same mesh and animation frames.

So it would appear that I am simply trying to do too much at a time. Also, my world Poly's in "Camera View" at a time are around 115k (1.2mil in total), NOT including the SciFiGuys running around- thats just the scene.

Which makes me think of something. I recently scene an Interview on G4 with CliffyB on his new game, and they are really only dealing with about 5 badguys at a time- or at least thats the footage they showed on TV.

So perhaps my overall world design, and monster population is just too much for B3D or maybe even a game period. If I had to sum up my game into 1 word...it would be "Pressure".

Any thoughts on any of this ?


CodeOrc(Posted 2008) [#31]
Well, I figured out a way to make my ActorUpdate() only operate/handle the monsters per a given active area.

So I can load up to 200 monsters, but only operate 25 at a time to maintain 60 FPS.

thx again to all who helped, and StevieG, your a genius !!

Hopefully this thread will be as valuable to others as it has been to me.