EntiyCollided .vs EntityDistance

Blitz3D Forums/Blitz3D Beginners Area/EntiyCollided .vs EntityDistance

CodeOrc(Posted 2007) [#1]
Hi,

Is there a performance difference using EntityCollided .vs EntityDistance ?

Meaning, say I want to know if a badguy hits me, but he is obviously at a distance of 3 from me. Is there a speed diff between the 2 above mentioned functions for my uses?

I currently have it tracking 200 monsters and all the fun that goes with it, just wondering if I can increase performance using one function over the other.

thx :)


chwaga(Posted 2007) [#2]
difference is: entitycollided can do polygon-sphere collisions, or sphere-sphere collisions. entitydistance forms a sphere of n radius about the object's pivot. Unless the pivot is located at the center of the object, entitydistance should not be used. Entitycollided says if this entity has collided with any object at all, meaning, object-to-object checking couldnt be done with entitycollided. Entitycollided is used for things like "if this entity is not touching anything at all then move it down" (gravity). entitydistance goes off the xyz position of the object, so if it's y position is located at the object's feet, you'll have an invisible sphere of n radius located at the person's feet, which could get messy.

They both have pros and cons, though there's probably some other command I dont know of. MeshIntersect does entity-to-entity check, but it's very slow if you have heavy meshes.


boomboom(Posted 2007) [#3]
He didn't want to know the definition of them, I am sure he knows what each one does already. He wants speed comparisons


chwaga(Posted 2007) [#4]
I don't see you giving speed comparisons :P


CodeOrc(Posted 2007) [#5]
@ chwaga - Thank you for the detailed info. I know what they do, but it never hurts to get others info/point-of-view on commands. Especially when posted in the Beginner area and a Beginner reads it :)

@ boomboom - yes, speed is what I am after

I use both for diff things as required. Was just wondering if by using one over the other in certain cases, would frames per second be increased?


boomboom(Posted 2007) [#6]
I gave him more than speed comparisons....I gave him hope


boomboom(Posted 2007) [#7]
.


CodeOrc(Posted 2007) [#8]
Oh, chwaga, just seen you site, nice man. Not to get off my own topic, but how did you get bump mapping working on your candles?


Sledge(Posted 2007) [#9]
I would expect EntityCollided to be slower than EntityDistance simply because it does more (ie prevents intersection*) and most likely encompasses a distance calculation. I don't want to sound flippant but the way to confirm which is faster in your given situation is to test it and see ;)


*EDIT: EntityCollided is, of course, dependant upon Blitz's internal collision system so remember that when I say I expect EntityDistance to be quicker than EntityCollided what I mean is I expect EntityDistance to be quicker than setting up enemy-to-player Blitz collisions maintained with UpdateWorld and interrogated with EntityCollided. Just dropping the EntityCollided command alone is not going to circumvent the process that does the work keeping track of the collisions... remember that when you're comparing one method with the other.


puki(Posted 2007) [#10]
Many Blitzers in the past have declared EntityDistance to be faster. However, I would assume that the difference is dependent on how far you are checking the distance.


chwaga(Posted 2007) [#11]
if you're already doing collisions, shouldnt entitycollided just be a simple reference to an internal collision variable, while entitydistance does a small equation? If this is the case, entitycollided would be faster.

(CodeOrc, thanks for the feedback, the candles were done & rendered in 3ds, plus i did a ton of blobmesh and other stuff to it, uber laggy :D )


Sledge(Posted 2007) [#12]
if you're already doing collisions, shouldnt entitycollided just be a simple reference to an internal collision variable, while entitydistance does a small equation?

That's what I'm getting at in my edited reply... 'EntityCollided or EntityDistance?' isn't a meningful question if you don't know whether or not the internal collisions associated with those objects can be dropped.

To be honest, unless the speed difference was significant, I would simply opt for the one that made the code easiest to maintain. Readability trumps speed any day.


big10p(Posted 2007) [#13]
Many Blitzers in the past have declared EntityDistance to be faster. However, I would assume that the difference is dependent on how far you are checking the distance.
Nah. EntityDistance is just an implementation of Pythagoras' Theorem, the execution speed of which isn't dependant on the distances involved.


MadJack(Posted 2007) [#14]
Don't know about this - surely the updateworld (collisions) process includes a distance check in itself?

I remember I added an entitydistance check in my game code a little while ago (entitydistance(camera,object), and I noticeably lost framerate.


Ross C(Posted 2007) [#15]
Entitydistance is super quick. As big10p says, it's a simple calculation. You could use 1,000's of these everyloop without any meaningful slowdown. I have done this is in a few projects, and it comes in handy.

For instance, say you had coins to collect, you wouldn't really bother set up collisions, as you don't want a collision responce, and the collision your looking for is very simple.