You go squish NOW!!!! please....

Blitz3D Forums/Blitz3D Programming/You go squish NOW!!!! please....

thelizardking(Posted 2006) [#1]
For some reason, whenever I get close to the diamond model, all of them completely dissapear, when I just want one to dissapear. PLEASE HELP!!!!! I need to know how to get just one, when collided, to dissapear.

CallDLL("seticon","SetIconLg")

AppTitle "Dementia"

Graphics3D 1280,1024
SetBuffer BackBuffer()
SeedRnd Millisecs()
...
Global TYPE_PLAYER=1
...

lvl_f=ReadFile("Data\Levels\lavahell.txt")
dia=LoadMesh("Data\Meshes\diamond.3DS")

lvl_l$=ReadLine(lvl_f);This is junk line for users
While Not Eof(lvl_f)
diam.diam=New diam
diam\mesh=CopyEntity(dia)
ScaleEntity diam\mesh,0.06,0.06,0.06
diam\x#=ReadLine(lvl_f)
diam\y#=ReadLine(lvl_f)
diam\z#=ReadLine(lvl_f)
PositionEntity diam\mesh,diam\x#,diam\y#,diam\z#
EntityType diam\mesh,TYPE_DIAMOND
Wend

CloseFile lvl_f
...

Collisions TYPE_PLAYER,TYPE_DIAMOND,2,2

While Not KeyHit(1)
...
For diam.diam=Each diam
TurnEntity diam\mesh,0,1,0
If EntityX(plr)-diam\x#>=MeshWidth(diam\mesh)*0.06 Or EntityX(plr)-diam\x#<=MeshWidth(diam\mesh)*0.06
;Continue the same Entity_(plr)-diam\__=Mesh_(diam\mesh)*0.06
HideEntity diam\mesh:Delete diam
EndIf
EndIf
EndIf
Next
...
UpdateWorld
RenderWorld
...
Flip
Wend


b32(Posted 2006) [#2]
I think the main problem is the comparisation, where you are checking if the X distance is both greater than and smaller than the width * 0.06.
When you are using more than one expressions in an If statement, it is best to use brackets. And/Or/Xor in BB are bitwise operators, and that has something to do with why brackets are safest.
Instead of calculating the distance yourself, try using EntityDistance(diam\mesh, plr) instead:
If EntityDistance(..) < 0.12 then .. etc


thelizardking(Posted 2006) [#3]
I tried using If EntityDistance(plr,diam\mesh)<3 Then YouKnowWhatHappensHere, but once I ran into a diamond, all the diamonds go away...ALL of them. So I did dis#=EntityDistance(plr,diam\mesh)...Text 0,0,dis# and it was like the distance from the newest created diamond mesh...but I put it in the For diam.diam=Each diam...Next loop. For some reason, it seems the problem is in the For...Next loop, and it is literally doing EACH diamond mesh, even if just one mesh is collided.


b32(Posted 2006) [#4]
That is strange, when you are doing Text 0, 0, dis# it should write all the distances of every diamon on the same spot. Maybe it is the collisions, try commenting them out ? Otherwise there might be something wrong with the loop maybe, or the distance between the diamons themselves is smaller than 3.


Shambler(Posted 2006) [#5]
Please post your current code for us to see.

It looks like your test for distance is wrong.

See this example...




Sir Gak(Posted 2006) [#6]
Hi, here is what may be causing your problem. You are using the "CopyEntity" command. But, the Help on this command says that anything you do to the original mesh, affects the copies. When you delete the one "diamond", I think you in effect delete ALL of them! Try using CopyMesh instead. (Of course, if you WANT all copies to disappear, then CopyEntity could be a very useful tool to that end.)

CopyEntity ( entity[,parent] )
Parameters
entity - Entity Handle
parent (optional) - Entity that will act as Parent to the copy.

Description
Creates a copy of an entity and returns the handle of the newly created copy. This is a new entity instance of an existing entity's mesh! Anything you do to the original Mesh (such as RotateMesh) will effect all the copies. Other properties (such as EntityColor, Position etc.) since they are 'Entity' properties, will be individual to the copy.

If a parent entity is specified, the copied entity will be created at the parent entity's position. Otherwise, it will be created at 0,0,0.


Shambler(Posted 2006) [#7]
This would be true if he hid or freed the original mesh 'dia' but he isn't (as far as we know ) ;), he is only hiding the meshes that belong to the type diam.

He should be able to delete any of the diam types since none of them contains the original mesh.


Sir Gak(Posted 2006) [#8]
To the best of my knowledge (which admittedly isn't top-notch) I believe the EntityCopy does not make a new mesh, but "copies" it from the original, which is why any changes to the original automaticaly happen to the copies. So, if I understand this correctly, there are NOT independent meshes he can delete, as there would be if he used CopyMesh. Of course I could be mistaken,. but I believe what happens to one mesh, happens to all (of those made using CopyEntity). Maybe someone could put together some test code to try this out (I'm working late at the job at the moment, so I can't get to it here.)

If I'm mistaken, I'd like to know, so as to further hone and better my understanding of B3D.

So, can someone throw together some code and see which way the wind blows on this?


Stevie G(Posted 2006) [#9]
You are mistaken Sir Gak. Taking a copy of the entity simply creates a new entity which shares the geometry and brush properties of the original mesh. Obviously the brush properties can be overwritten on the copy but freeing the copied entity will leave the original mesh untouched.

If you changed the vertices etc.. on the original mesh it would affect each Entity which was a copy but not the brush properties.

This may have been mentioned above so apologies if it has but ..

This line :
HideEntity diam\mesh:Delete diam

Should be:
freeEntity diam\mesh:Delete diam


As once you've deleted the type instance, the entity will still exist but you will have no way of accessing it.

You should also hideentity the dia mesh after it's loaded as you're only using it as a blueprint for the others.

I hope this makes sense?

Stevie


Sir Gak(Posted 2006) [#10]
OK, I'm mistaken. Better to find out, than to continue in my "mistakeness"! <grin>

So, do we have a "fix" for the original problem facing thelizardking? His problem was not in getting one entity to disappear, but rather when he did it, they ALL went away.

Since he is doing a FOR-Each loop, the "IF" condition is obviously always coming "true", so it is deleting all the diamonds. He needs a better "IF" statement conditional check where it can give a genuine TRUE/FALSE answer, and definitely delete only the one he has collided with.

As I think about it, he should just check to see if a collision has occurred using the B3D commands, instead of trying to figure out computationally which was closest. In other words, you know you are "close" because Blitz tracks whether you collided with it. Then, you don't need to compute how far away they were.


Shambler(Posted 2006) [#11]
Without seeing his current code it is hard to fix it but I did post some working code above that he should be able to adapt.

If we knew how close together his diamonds were and how large each diamond was we could offer more help.


Sir Gak(Posted 2006) [#12]
In my last post, I said he is deleting all his diamonds. Actually, he is deleting the types, not entity instances. The latter are merely being "hidden", not deleted.


slenkar(Posted 2006) [#13]
Lizard King, put the game in debug mode and put

debuglog "diamond squished"

next to the line where you are hiding the diamond entity.
Then you can see how many times diamonds are being hidden.


thelizardking(Posted 2006) [#14]
k thnxs i fixed it with this help ('all' meaning pretty much everything combined) so thnxs


Sir Gak(Posted 2006) [#15]
Best part of this forum is when the community pitches in to help out, and the problem gets solved.