There may be no such thing as a dumb question, but this one surely is. How do you use the command EntityCollided?
Dumb Question
Blitz3D Forums/Blitz3D Beginners Area/Dumb Question Well say you want the handle of the tree your player is collided with.
Players are collision type 1
Trees are collision type 2
Ground is collision type 3
(these above are just example collision type numbers, you set them with the EntityType command)
You can't just check for generic collisions, becuase your player will probably be collided with the tree and the ground. So you are just looking for what tree hes collided with, which is type 2.
CollidedTreeName = EntityCollided(Player,2)
Players are collision type 1
Trees are collision type 2
Ground is collision type 3
(these above are just example collision type numbers, you set them with the EntityType command)
You can't just check for generic collisions, becuase your player will probably be collided with the tree and the ground. So you are just looking for what tree hes collided with, which is type 2.
CollidedTreeName = EntityCollided(Player,2)
This is my code:
But nothing happens. It doesn't even say "sup?" in the debug log.
For building.building = Each building If EntityCollided(bubble\entity, 3) FreeEntity building\entity Delete building DebugLog "Sup?" EndIf Next
But nothing happens. It doesn't even say "sup?" in the debug log.
have you set your collisions? Like:
Collisions 1,2,1,3
Collisions 1,2,1,3
I get it now. Thanks, guys.
Hmm. I changed it to n8r2k's suggestion, but it still doesn't work!
Also, my game involves a sphere rolling around. The sphere is pivoted around a point so it can roll, but not go into the ground. When the sphere crashes into stuff, it seems the pivot continues moving. Any advice?
Also, my game involves a sphere rolling around. The sphere is pivoted around a point so it can roll, but not go into the ground. When the sphere crashes into stuff, it seems the pivot continues moving. Any advice?
Don't forget to call UpdateWorld which is when collisions are actually detected.
You will have to put a trigger for the pivot in the collision check so that it, too will stop moving when the sphere stops moving
If my line didnt work than skid is right. You need to add UpdateWorld somewhere near the end of the mainloop,
double post sorry again.
dang, 2 double posts in one day. I havent had one in a long time
dang, 2 double posts in one day. I havent had one in a long time
If you can't get it to work, prob best to post up your entire code. Collisions have quite a few things that need to be placed to get them working.
"When the sphere crashes into stuff, it seems the pivot continues moving. Any advice?"
Enable collision on the pivot rather than on the sphere..
Enable collision on the pivot rather than on the sphere..
Here's the entire code, as requested:
Graphics3D 800, 600 SeedRnd MilliSecs() WireFrame 0 ;CONSTANTS Const leftkey = 203, rightkey = 205, upkey = 200, downkey = 208 Const spacebar = 57, enter = 28 Const gravity# = -.04 Global increase# ;Type building ;Field entity ;Field collision ;End Type ;For n = 0 To Rand(20) ; building.building = New building ; building\entity = CreateCube() ; ScaleEntity building\entity, 3, 20, 3 ; building\collision = 3 ; EntityType building\entity, building\collision ; PositionEntity building\entity, Rand(-30, 30), 0, Rand(-30, 30) ;Next Type bubble Field entity Field alpha# Field size# End Type ;TYPES Type sphere Field shape Field pivot Field vzlimit# Field collision Field slowdown# Field inertia# Field arrow Field burnout Field burntout Field exhaustpipe End Type light = CreateLight() PositionEntity light, 0, 0, 0 camera = CreateCamera() PositionEntity camera, 30, 10, 0 ground = CreateCube() PositionEntity ground, 0, -1, 0 ScaleEntity ground, 100, .1, 100 Global sphere.sphere = New sphere sphere\pivot = CreatePivot() sphere\shape = CreateSphere(8, sphere\pivot) PositionEntity sphere\pivot, 0, 1, 0 sphere\collision = 1 sphere\vzlimit# = 1.5 sphere\slowdown# = .02 sphere\inertia# = 0 sphere\burnout = 0 sphere\burntout = 0 sphere\exhaustpipe = CreateCylinder(8, True, sphere\pivot) ScaleEntity sphere\exhaustpipe, .3, .8, .3 RotateEntity sphere\exhaustpipe, 90, 0, 0 PositionEntity sphere\exhaustpipe, EntityX(sphere\shape) + .2, EntityY(sphere\shape) - .2, EntityZ(sphere\shape) - 1 texture = LoadTexture("blitzlogo.bmp", 64) EntityTexture sphere\exhaustpipe, texture EntityType sphere\shape, sphere\collision ScaleEntity sphere\shape, .85, 1, 1 spheretex = LoadTexture("blitzlogo2.bmp") ScaleTexture spheretex,.125,.25 RotateTexture spheretex, 90 EntityTexture sphere\shape, spheretex Global groundcollision = 2 EntityType ground, groundcollision EntityTexture ground, spheretex Collisions 3, 4, 3, 1 Collisions sphere\collision, groundcollision, 2, 2 Collisions sphere\collision, 3, 2, 1 Collisions sphere\collision, sphere\collision, 2, 2 SetBuffer BackBuffer() While Not KeyDown(1) PointEntity camera, sphere\shape move() bubbles() burnout() UpdateWorld RenderWorld Text 0, 0, "Onscreen Triangles: " + TrisRendered() Text 0, 10, "Player's Y Coordinates: " + EntityY(sphere\shape) Text 0, 20, "Pivot's Y Coordinates: " + EntityY(sphere\pivot) Text 0, 30, "Inertia: " + sphere\inertia# Text 0, 40, "increase: " + increase# Text 0, 50, "Burnout: " + sphere\burnout Text 0, 60, "Burnt out: " + sphere\burntout Rect 620, 560, 152, 20, 0 Color 255, 0, 0 Rect 621, 561, sphere\inertia#*100, 18, 1 If sphere\burntout = 0 If sphere\burnout Mod 20 > 0 And sphere\burnout Mod 20 < 11 Text 400, 500, "W A R N I N G : B U R N O U T", True, False EndIf Else Text 400, 500, "Engine Burnt Out", True, False EndIf Color 255, 255, 255 Text 697, 570, "S P E E D", True, True Flip Delay 15 Wend Function bubbles() For bubble.bubble = Each bubble MoveEntity bubble\entity, Rnd(-.1, .1), .2, 0 bubble\size# = bubble\size# + .1 ScaleEntity bubble\entity, bubble\size#, bubble\size#, bubble\size# bubble\alpha# = bubble\alpha# - .05 EntityAlpha bubble\entity, bubble\alpha# ;For building.building = Each building ;collido = EntityCollided(bubble\entity, 3) ;Print collido ;WaitKey ;If collido <> 0 ;FreeEntity building\entity ;Delete building ;DebugLog "Sup?" ;EndIf ;Next If bubble\alpha# < .1 FreeEntity bubble\entity Delete bubble EndIf Next If Rand(5) = 5 And sphere\inertia# > 0 bubble.bubble = New bubble bubble\entity = CreateSphere(6, sphere\exhaustpipe) bubble\alpha# = 1 bubble\size# = Rnd(1) ScaleEntity bubble\entity, bubble\size#, bubble\size#, bubble\size# EntityColor bubble\entity, 0, 0, 0 PositionEntity bubble\entity, 0, 0, + 1 EntityParent bubble\entity, 0 EntityType bubble\entity, 4 EndIf End Function Function move() If KeyDown(rightkey) TurnEntity sphere\pivot, 0, -5, 0 EndIf If KeyDown(leftkey) TurnEntity sphere\pivot, 0, 5, 0 EndIf If KeyDown(upkey) And sphere\burntout = 0;if the engine's workin', go! If sphere\burnout > 0 sphere\burnout = sphere\burnout + 1 EndIf If sphere\inertia# < sphere\vzlimit# increase# = (sphere\vzlimit# - sphere\inertia#)/25 sphere\inertia# = sphere\inertia# + increase# EndIf Else If KeyDown(downkey) sphere\inertia# = sphere\inertia# - sphere\slowdown#*3 EndIf sphere\inertia# = sphere\inertia# - sphere\slowdown# If sphere\inertia# < 0 sphere\inertia# = 0 sphere\burntout = 0 sphere\burnout = 0 EndIf EndIf If sphere\inertia# > sphere\vzlimit# sphere\inertia# = sphere\vzlimit# ElseIf sphere\inertia# < -sphere\vzlimit#/2 sphere\inertia# = -sphere\vzlimit#/2 EndIf TurnEntity sphere\shape, sphere\inertia#*40, 0, 0 MoveEntity sphere\pivot, 0, 0, sphere\inertia# PositionEntity sphere\exhaustpipe, EntityX(sphere\shape) + .2, EntityY(sphere\shape) - .2, EntityZ(sphere\shape) - 1 End Function Function burnout() If sphere\burnout > 1000 sphere\burntout = 1 EndIf If sphere\inertia# > 1.0 And sphere\burnout = 0;if the engine gets hot, it'll burn out! sphere\burnout = 1 EndIf End Function
Graphics3D 800, 600 SeedRnd MilliSecs() WireFrame 0 ;CONSTANTS Const leftkey = 203, rightkey = 205, upkey = 200, downkey = 208 Const spacebar = 57, enter = 28 Const gravity# = -.04 Global increase# Global spherecollision = 1 Global groundcollision = 2 Global buildingcollision = 3 Type building Field entity End Type For n = 0 To Rand(20) SeedRnd MilliSecs():Delay 1 building.building = New building building\entity = CreateCube() ScaleEntity building\entity, 3, 20, 3 EntityType building\entity, buildingcollision PositionEntity building\entity, Rand(-30, 30), 0, Rand(-30, 30) Next Type bubble Field entity Field alpha# Field size# End Type ;TYPES Type sphere Field shape Field pivot Field vzlimit# Field slowdown# Field inertia# Field arrow Field burnout Field burntout Field exhaustpipe End Type light = CreateLight() PositionEntity light, 0, 0, 0 camera = CreateCamera() PositionEntity camera, 30, 10, 0 ground = CreateCube() PositionEntity ground, 0, -1, 0 ScaleEntity ground, 100, .1, 100 Global sphere.sphere = New sphere sphere\pivot = CreatePivot() sphere\shape = CreateSphere(8, sphere\pivot) PositionEntity sphere\pivot, 0, 1, 0 sphere\vzlimit# = 1.5 sphere\slowdown# = .02 sphere\inertia# = 0 sphere\burnout = 0 sphere\burntout = 0 sphere\exhaustpipe = CreateCylinder(8, True, sphere\pivot) ScaleEntity sphere\exhaustpipe, .3, .8, .3 RotateEntity sphere\exhaustpipe, 90, 0, 0 PositionEntity sphere\exhaustpipe, EntityX(sphere\shape) + .2, EntityY(sphere\shape) - .2, EntityZ(sphere\shape) - 1 ;texture = LoadTexture("blitzlogo.bmp", 64) ;EntityTexture sphere\exhaustpipe, texture EntityType sphere\pivot, spherecollision ScaleEntity sphere\shape, .85, 1, 1 ; spheretex = LoadTexture("blitzlogo2.bmp") ; ScaleTexture spheretex,.125,.25 ; RotateTexture spheretex, 90 ; EntityTexture sphere\shape, spheretex EntityType ground, groundcollision ;EntityTexture ground, spheretex Collisions 3, 4, 3, 1 Collisions spherecollision, groundcollision, 2, 2 Collisions spherecollision, 3, 2, 1 Collisions spherecollision, spherecollision, 2, 2 SetBuffer BackBuffer() While Not KeyDown(1) PointEntity camera, sphere\shape move() bubbles() burnout() UpdateWorld RenderWorld Text 0, 0, "Onscreen Triangles: " + TrisRendered() Text 0, 10, "Player's Y Coordinates: " + EntityY(sphere\shape) Text 0, 20, "Pivot's Y Coordinates: " + EntityY(sphere\pivot) Text 0, 30, "Inertia: " + sphere\inertia# Text 0, 40, "increase: " + increase# Text 0, 50, "Burnout: " + sphere\burnout Text 0, 60, "Burnt out: " + sphere\burntout Rect 620, 560, 152, 20, 0 Color 255, 0, 0 Rect 621, 561, sphere\inertia#*100, 18, 1 If sphere\burntout = 0 If sphere\burnout Mod 20 > 0 And sphere\burnout Mod 20 < 11 Text 400, 500, "W A R N I N G : B U R N O U T", True, False EndIf Else Text 400, 500, "Engine Burnt Out", True, False EndIf Color 255, 255, 255 Text 697, 570, "S P E E D", True, True Flip Delay 15 Wend Function bubbles() For bubble.bubble = Each bubble MoveEntity bubble\entity, Rnd(-.1, .1), .2, 0 bubble\size# = bubble\size# + .1 ScaleEntity bubble\entity, bubble\size#, bubble\size#, bubble\size# bubble\alpha# = bubble\alpha# - .05 EntityAlpha bubble\entity, bubble\alpha# ;For building.building = Each building ;collido = EntityCollided(bubble\entity, 3) ;Print collido ;WaitKey ;If collido <> 0 ;FreeEntity building\entity ;Delete building ;DebugLog "Sup?" ;EndIf ;Next If bubble\alpha# < .1 FreeEntity bubble\entity Delete bubble EndIf Next If Rand(5) = 5 And sphere\inertia# > 0 bubble.bubble = New bubble bubble\entity = CreateSphere(6, sphere\exhaustpipe) bubble\alpha# = 1 bubble\size# = Rnd(1) ScaleEntity bubble\entity, bubble\size#, bubble\size#, bubble\size# EntityColor bubble\entity, 0, 0, 0 PositionEntity bubble\entity, 0, 0, + 1 EntityParent bubble\entity, 0 EntityType bubble\entity, 4 EndIf End Function Function move() If KeyDown(rightkey) TurnEntity sphere\pivot, 0, -5, 0 EndIf If KeyDown(leftkey) TurnEntity sphere\pivot, 0, 5, 0 EndIf If KeyDown(upkey) And sphere\burntout = 0;if the engine's workin', go! If sphere\burnout > 0 sphere\burnout = sphere\burnout + 1 EndIf If sphere\inertia# < sphere\vzlimit# increase# = (sphere\vzlimit# - sphere\inertia#)/25 sphere\inertia# = sphere\inertia# + increase# EndIf Else If KeyDown(downkey) sphere\inertia# = sphere\inertia# - sphere\slowdown#*3 EndIf sphere\inertia# = sphere\inertia# - sphere\slowdown# If sphere\inertia# < 0 sphere\inertia# = 0 sphere\burntout = 0 sphere\burnout = 0 EndIf EndIf If sphere\inertia# > sphere\vzlimit# sphere\inertia# = sphere\vzlimit# ElseIf sphere\inertia# < -sphere\vzlimit#/2 sphere\inertia# = -sphere\vzlimit#/2 EndIf TurnEntity sphere\shape, sphere\inertia#*40, 0, 0 MoveEntity sphere\pivot, 0, 0, sphere\inertia# PositionEntity sphere\exhaustpipe, EntityX(sphere\shape) + .2, EntityY(sphere\shape) - .2, EntityZ(sphere\shape) - 1 End Function Function burnout() If sphere\burnout > 1000 sphere\burntout = 1 EndIf If sphere\inertia# > 1.0 And sphere\burnout = 0;if the engine gets hot, it'll burn out! sphere\burnout = 1 EndIf End Function
Just thought I'd comment on 'dumb question'
My take on it is simple:
The only dumb question is the one that is never asked. :D
My take on it is simple:
The only dumb question is the one that is never asked. :D
boomboom, did he just setup types wrong? I cant tell without reading the whole code.
Yea. And then was applying the collision to a sphere, but driving the pivot, so it would all go out of sync.
boomboom: Thanks a bunch!
Can you please tell me:
The changes you made to the code
Why the bubbles don't delete the buildings
Everyone, thanks so much for your input.
Can you please tell me:
The changes you made to the code
Why the bubbles don't delete the buildings
Everyone, thanks so much for your input.
the exaust bubbles delete buildings now. I dont know why youd want them to, unless your making a statment about pollution. i put a line of dashes after the changes i made.
I dont have time to look through and see what boomboom did but maybe he could add comments to what he did.
Graphics3D 800, 600 SeedRnd MilliSecs() WireFrame 0 ;CONSTANTS Const leftkey = 203, rightkey = 205, upkey = 200, downkey = 208 Const spacebar = 57, enter = 28 Const gravity# = -.04 Global increase# Global spherecollision = 1 Global groundcollision = 2 Global buildingcollision = 3 Global collido Type building Field entity End Type For n = 0 To Rand(20) SeedRnd MilliSecs():Delay 1 building.building = New building building\entity = CreateCube() ScaleEntity building\entity, 3, 20, 3 EntityType building\entity, buildingcollision PositionEntity building\entity, Rand(-30, 30), 0, Rand(-30, 30) Next Type bubble Field entity Field alpha# Field size# End Type ;TYPES Type sphere Field shape Field pivot Field vzlimit# Field slowdown# Field inertia# Field arrow Field burnout Field burntout Field exhaustpipe End Type light = CreateLight() PositionEntity light, 0, 0, 0 camera = CreateCamera() PositionEntity camera, 30, 10, 0 ground = CreateCube() PositionEntity ground, 0, -1, 0 ScaleEntity ground, 100, .1, 100 Global sphere.sphere = New sphere sphere\pivot = CreatePivot() sphere\shape = CreateSphere(8, sphere\pivot) PositionEntity sphere\pivot, 0, 1, 0 sphere\vzlimit# = 1.5 sphere\slowdown# = .02 sphere\inertia# = 0 sphere\burnout = 0 sphere\burntout = 0 sphere\exhaustpipe = CreateCylinder(8, True, sphere\pivot) ScaleEntity sphere\exhaustpipe, .3, .8, .3 RotateEntity sphere\exhaustpipe, 90, 0, 0 PositionEntity sphere\exhaustpipe, EntityX(sphere\shape) + .2, EntityY(sphere\shape) - .2, EntityZ(sphere\shape) - 1 ;texture = LoadTexture("blitzlogo.bmp", 64) ;EntityTexture sphere\exhaustpipe, texture EntityType sphere\pivot, spherecollision ScaleEntity sphere\shape, .85, 1, 1 ; spheretex = LoadTexture("blitzlogo2.bmp") ; ScaleTexture spheretex,.125,.25 ; RotateTexture spheretex, 90 ; EntityTexture sphere\shape, spheretex EntityType ground, groundcollision ;EntityTexture ground, spheretex Collisions 4,3,3,1 ;------------------boomboom and buggy forgot to check bubblecollisions with buildings Collisions 3, 4, 3, 1 ;-------------they only check to see if building was going to run into the bubble, which isnt going to happen Collisions spherecollision, groundcollision, 2, 2 Collisions spherecollision, 3, 2, 1 Collisions spherecollision, spherecollision, 2, 2 SetBuffer BackBuffer() While Not KeyDown(1) PointEntity camera, sphere\shape move() bubbles() burnout() UpdateWorld RenderWorld Text 0, 0, "Onscreen Triangles: " + TrisRendered() Text 0, 10, "Player's Y Coordinates: " + EntityY(sphere\shape) Text 0, 20, "Pivot's Y Coordinates: " + EntityY(sphere\pivot) Text 0, 30, "Inertia: " + sphere\inertia# Text 0, 40, "increase: " + increase# Text 0, 50, "Burnout: " + sphere\burnout Text 0, 60, "Burnt out: " + sphere\burntout Text 0,70,collido Rect 620, 560, 152, 20, 0 Color 255, 0, 0 Rect 621, 561, sphere\inertia#*100, 18, 1 If sphere\burntout = 0 If sphere\burnout Mod 20 > 0 And sphere\burnout Mod 20 < 11 Text 400, 500, "W A R N I N G : B U R N O U T", True, False EndIf Else Text 400, 500, "Engine Burnt Out", True, False EndIf Color 255, 255, 255 Text 697, 570, "S P E E D", True, True Flip Delay 15 Wend Function bubbles() For bubble.bubble = Each bubble MoveEntity bubble\entity, Rnd(-.1, .1), .2, 0 bubble\size# = bubble\size# + .1 ScaleEntity bubble\entity, bubble\size#, bubble\size#, bubble\size# bubble\alpha# = bubble\alpha# - .05 EntityAlpha bubble\entity, bubble\alpha# For building.building = Each building If EntityCollided(bubble\entity, 3) = building\entity ;---------checked to see if bubble collided with building FreeEntity building\entity ;-----------freed the building Delete building ;-------------- deleted the building EndIf Next If bubble\alpha# < .1 FreeEntity bubble\entity Delete bubble EndIf Next If Rand(5) = 5 And sphere\inertia# > 0 bubble.bubble = New bubble bubble\entity = CreateSphere(6, sphere\exhaustpipe) bubble\alpha# = 1 bubble\size# = Rnd(1) ScaleEntity bubble\entity, bubble\size#, bubble\size#, bubble\size# EntityColor bubble\entity, 0, 0, 0 PositionEntity bubble\entity, 0, 0, + 1 EntityParent bubble\entity, 0 EntityType bubble\entity, 4 EndIf End Function Function move() If KeyDown(rightkey) TurnEntity sphere\pivot, 0, -5, 0 EndIf If KeyDown(leftkey) TurnEntity sphere\pivot, 0, 5, 0 EndIf If KeyDown(upkey) And sphere\burntout = 0;if the engine's workin', go! If sphere\burnout > 0 sphere\burnout = sphere\burnout + 1 EndIf If sphere\inertia# < sphere\vzlimit# increase# = (sphere\vzlimit# - sphere\inertia#)/25 sphere\inertia# = sphere\inertia# + increase# EndIf Else If KeyDown(downkey) sphere\inertia# = sphere\inertia# - sphere\slowdown#*3 EndIf sphere\inertia# = sphere\inertia# - sphere\slowdown# If sphere\inertia# < 0 sphere\inertia# = 0 sphere\burntout = 0 sphere\burnout = 0 EndIf EndIf If sphere\inertia# > sphere\vzlimit# sphere\inertia# = sphere\vzlimit# ElseIf sphere\inertia# < -sphere\vzlimit#/2 sphere\inertia# = -sphere\vzlimit#/2 EndIf TurnEntity sphere\shape, sphere\inertia#*40, 0, 0 MoveEntity sphere\pivot, 0, 0, sphere\inertia# PositionEntity sphere\exhaustpipe, EntityX(sphere\shape) + .2, EntityY(sphere\shape) - .2, EntityZ(sphere\shape) - 1 End Function Function burnout() If sphere\burnout > 1000 sphere\burntout = 1 EndIf If sphere\inertia# > 1.0 And sphere\burnout = 0;if the engine gets hot, it'll burn out! sphere\burnout = 1 EndIf End Function
I dont have time to look through and see what boomboom did but maybe he could add comments to what he did.
Thanks, n8. I didn't realize there was a difference between the buildings running into the bubbles and vice versa. There's no reason why, I'm just testing different things.
Why is it that all of the buildings delete at once though?
Why is it that all of the buildings delete at once though?
let me see. I thought i fixed that
Well I added color so i could see what i was doing, the collide and then delete process is a little choppy, your going to have to work on that, unless i come up with something in my sleep, but they delete when the bubbles run into them.
i replaced:
with this:
when i realized that it was deleting buildings when the player runs into anything.
can you be more specific on what is happening
i replaced:
If EntityCollided((bubble\entity,3) <> 0
with this:
If EntityCollided(bubble\entity, 3) = building\entity
when i realized that it was deleting buildings when the player runs into anything.
can you be more specific on what is happening
Yes, yours works. What is happening? I'm just experimenting with deleting entities and such.
Also, why is it that if I add the command
in the beginning, after a building is deleted, the sphere goes all crazy?
Any more wonderful help?
Also, why is it that if I add the command
EntityType sphere\exhaustpipe, spherecollision
in the beginning, after a building is deleted, the sphere goes all crazy?
Any more wonderful help?
I am not sure right now but it might be that you are setting the exaust pipe to collide with the sphere car thing.
If i have time later I can see what you mean.
If i have time later I can see what you mean.