Plain Ol' Help

Blitz3D Forums/Blitz3D Beginners Area/Plain Ol' Help

Buggy(Posted 2006) [#1]
I need help.

I thought it would be cool if I had little black spheres representing smoke to come out of the exhaust pipe of my car-like things in my latest game-like thing. They would rise up and fade away, in which case I'd delete them.

Well, I'm not too good at Blitz3D... yet, but I tried... and failed miserably.

Here's the pertinent code:

Function bubbles()
	
	For bubble.bubble = Each bubble
	
		MoveEntity bubble\entity, Rnd(-.1, .1), .2, Rnd(-.1, .1)
		ScaleEntity bubble\entity, 2.5, 2.5, 2.5, True
		bubble\alpha# = bubble\alpha# - .05
		EntityAlpha bubble\entity, bubble\alpha#
		Print bubble\alpha#
		WaitKey
		
		
		If bubble\alpha# < .1
		
			FreeEntity bubble\entity
			Return
			
		EndIf
		
	Next
	
	
	If Rand(5) = 5
	
		bubble.bubble = New bubble
		
			bubble\entity = CreateSphere(8)
			bubble\alpha = 1
			ScaleEntity bubble\entity, .1, .1, .1
			EntityColor bubble\entity, 0, 0, 0
			PositionEntity bubble\entity, EntityX(sphere\exhaustpipe), EntityY(sphere\exhaustpipe), EntityZ(sphere\exhaustpipe) - 2
		
	EndIf		
	
End Function


When an entity gets to the point of deletion, no matter what number I set for that point, an error pops up at me saying that the entity does not exist (it highlights the MoveEntity line).

If I try using "delete bubble\entity" instead of FreeEntity (is there a difference?), it says it "can't delete non-Newtype."

Furthermore, the bubbles always spawn from the same point, and not from the end of my exhaust pipe.

Basically, here are the big three questions:

1. How can I delete the bubbles?

2. Is there a difference between FreeEntity and Delete?

3. How can I make the bubbles not follow me, but spawn from the end of the exhaust pipe?


Ross C(Posted 2006) [#2]
FreeEntity frees the mesh, blitz is using, from memory.

Delete, works by deleting the type object you have created. If you use this on it's own, and you have fields which contain mesh,texture,sprite, sound handles attached (basically any form of media or handle), they will still remain in memory, with no link to them.

Your having problems because, you are freeing the mesh, but leaving behind the type object and the field "bubble\entity" reference to it.

You need to:

Free the mesh
Delete the type object.

FreeEntity bubble\entity
Delete bubble.bubble


As for you bubble not coming out of the exhaust, i believe it might have something to do with the entity XYZ positions getting taken from the exhausts PARENT. I believe the exhaust is parented to the car?

If so, you need to do:

PositionEntity bubble\entity, EntityX(sphere\exhaustpipe,true), EntityY(sphere\exhaustpipe,true), EntityZ(sphere\exhaustpipe,true) - 2,true


Use the global parameters in the EntityX Y and Z commands.


Sledge(Posted 2006) [#3]
1 & 2
FreeEntity whicheverbubble.bubble\entity, after which Delete whicheverbubble.bubble... you have to free the mesh that's assigned to *whichever* instance of your bubble type before you delete the instance itself. FreeEntity for meshes, Delete for instances of a type.

3
I would place a pivot at the exhaust of each car which acts as a generator. When you create a new instance of your bubble type you reference the global position of the car in question's generator pivot and place the new bubble's mesh there.


EDIT: Ross types faster than me, pun intended. ;)


Buggy(Posted 2006) [#4]
I thought about parenting the bubble to the exhaust, but figured they would follow it, then.

Thanks, guys.


Buggy(Posted 2006) [#5]
Well, the problem with deleting I had was that I typed delete bubble\entity, instead of delete bubble.

That's fixed, but I forgot to mention another problem. The bubbles don't grow. They just stay the same size.

Well, actually, they really start at their original size, grow once, and stop.


Matty(Posted 2006) [#6]
When you call 'scaleentity entity, 2.5,2.5,2.5' it scales the entity relative to the original mesh. So it will always be set to 2.5x the size of the original mesh. If you want it to continue to grow then you will need to increase the scale each time.


Sir Gak(Posted 2006) [#7]
Matty: Wouldn't ScaleMesh be better for that purpose?
From the B3D Help:
; ScaleMesh Example 
; ----------------- 

; In this example we will demonstrate the use of the ScaleMesh command. 

; Unlike ScaleEntity, ScaleMesh actually modifies the actual mesh structure. 

; So whereas using ScaleEntity 2,2,2 would only double the size of an entity the first time it was 
; used, ScaleMesh 2,2,2 will double the size of the mesh every time it is used. 

; This is because ScaleEntity scales an entity based on a fixed mesh structure, whereas ScaleMesh 
; actually modifies the mesh structure itself. 

Graphics3D 640,480 
SetBuffer BackBuffer() 

camera=CreateCamera() 

light=CreateLight() 

; Create cube mesh 
cube=CreateCube() 

; Position cube in front of camera so we can see it 
PositionEntity cube,0,0,5 

While Not KeyDown(1) 

; If space bar pressed then scale cube mesh by 1%. Also set syntax$ text. 
If KeyHit(57)=True Then ScaleMesh cube,1.01,1.01,1.01 : syntax$="ScaleMesh 1.01,1.01,1.01" 

RenderWorld 

Text 0,0,"Press space to scale mesh by 1%" 
Text 0,20,syntax$ 

Flip 

Wend 

End  



Ross C(Posted 2006) [#8]
Only problem with scale mesh, is it's harder to find out what scale something is at.


Sir Gak(Posted 2006) [#9]
ScaleMesh works relative to the current size of the mesh. If the smoke clouds from the tailpipe are supposed to grow and grow as they disperse, then ScaleMesh is perfect. Start with little black spheres at original size, and then scalemesh is used on the copies until they are deleted/freed up.


Ross C(Posted 2006) [#10]
It depends on whether there copied or not. I think if you scalemesh, and have done copyentity, each copy will be affected by the scalemesh.


Buggy(Posted 2006) [#11]
I figured that out the hard way, but thanks guys.

Actually, I'm not sure ScaleEntity is relative to the original mesh size...

Would it be quicker for me to use ScaleEntity each time and simply scale it by a marginally smaller number each time? For instance, in frame #1 I scale it by 1.5, and then in frame #2 I scale it by 1.499999 and it keeps growing, instead of slightly shrinking as it would if ScaleEntity was relative to the original size. Frame #3: 1.499998, etc.

Or would it be quicker for the computer to use ScaleMesh?

Basically, is ScaleMesh slower than ScaleEntity (as I imagine it would be)


Sir Gak(Posted 2006) [#12]
One way to find out is to build a little test prog, run a loop a few hundred-thousand times, using millisecs() for the before-and-after timings, and see which command is faster.


Sledge(Posted 2006) [#13]
Any difference in speed between using ScaleMesh and ScaleEntity to resize bubbles will be insignificant in comparison to the difference in rendering speed achieved by using CopyEntity rather than CopyMesh to create new bubbles. Your primary aim is to keep the surface count down.


Ross C(Posted 2006) [#14]
Indeed. In that case, copyentity would be your best bet, using a variable to update the size of the entity.


Buggy(Posted 2006) [#15]
I never have used CopyEntity or CopyMesh. Would it be easier to just make a new "car" altogether?


Sledge(Posted 2006) [#16]
We're talking about the "bubbles", not the cars.