EntityBox and ScaleEntity

Blitz3D Forums/Blitz3D Beginners Area/EntityBox and ScaleEntity

Chalky(Posted 2006) [#1]
Apologies in advance - but I am finally embarking on my first ever attempt at a 3D game, and have fallen at virtually the first hurdle!

I am creating an early mockup of what will eventually be a train game and am using cubes scaled into rectangles as crude trains so that I can code 'train selection with mouse click' via CameraPick.

I have searched the forums and code archives relating to EntityBox and ScaleEntity and am a little confused as to whether the two commands can be used successfully with a cube which has been stretched into a rectangle? I am able to create and scale uniform cubes and their EntityBoxes without problems (after which CameraPick works accurately every time), but if I create a rectangle using:

train=CreateCube()
ScaleEntity train,1,2,1
EntityBox train,-1,-1,-1,2,4,2
EntityPickMode train,3


CameraPick no longer works properly. Am I being a muppet and doing something stupid?

The online manual entry for EntityBox has additional information which says "the space the entity resides in should be scaled uniformly. EntityBox will not work as you might expect in non-uniform scaled space". Does this mean I cannot use EntityBox for rectangular collision detection, and if so how can I achieve this?

Any help would be gratefully appreciated!


b32(Posted 2006) [#2]
The box you entered is not centered, it should be EntityBox train,-1,-2,-1,2,4,2


Chalky(Posted 2006) [#3]
You're quite right b32! However, I have corrected the code and made a modification to the cube definitions (I was extending the Y axis and then rotating them so they lay on the floor - don't ask me why!) and whilst CameraPick now works ok, Collisions do not - unless I do not scale the cubes, in which case they work perfectly.

My code is as follows:



I must be doing something wrong somewhere - because no matter what I try, a "train" will pass almost 1/3 of the way through another before Blitz3D registers a collision. Can anyone tell me why my code does not work? (Apologies for the camera - another eve or two spent in the archives til I learn how to improve this methinks...) :o)


b32(Posted 2006) [#4]
I think the reason for that is that collisions are allways sphere to something. So, the 'emitting' entity is still represented by a sphere, and the 'receiving' entities are boxes. I changed the code a bit to make the EntityRadius visible:



Chalky(Posted 2006) [#5]
Thanks b32 - that function was very useful. I have now managed to get further progress by stretching the cubes along a different plane before specifying both EntityBox and EntityRadius:



However - EntityRadius seems to ignore the optional y_radius parameter and use the x_radius value for both instead. If you run the above code and move the middle "train" clear of the others, then move the others the same distance, both glide outwards as they slide round the middle train's y_radius boundary. This is no good to me since I need trains to run on adjacent tracks - which Blitz3D will currently prevent me doing since its collision detection will halt the trains if the tracks are close together.

I see in the forums that this y_radius behaviour was once thought to be a possible bug. I am now using v1.98 and can find nothing in the versions.txt to indicate this was fixed.

Does anyone know if this has ever been confirmed as a bug and if so whether a fix was issued?


b32(Posted 2006) [#6]
I thought it is like this: blitz uses the X-radius for X/Z and the Y for Y, and you can't rotate the EntityRadius, but maybe I'm wrong.


Chalky(Posted 2006) [#7]
Yeah I think your right - particularly as I have finally realised that it's the z-plane the entities are sliding in! Looks like I need to use the y-plane as the width and rotate it so that the z-plane becomes height - so I hope you're wrong about EntityRadius rotation (though I'm sure I've seen that mentioned somewhere in these forums too).

Seems odd that there's no z_radius parameter since entities are 3D and designed to be used in 3-planes. Mind you I notice that the y_radius was only introduced fairly recently, so really mustn't grumble...


Chalky(Posted 2006) [#8]
Ok - I admit defeat. RotateEntity evidently does not rotate the EntityRadius - and no matter what I do, I cannot get the collisions to work the way I need them to because of the fact that the x/z axis share the same radius, and so the moving "train" will always have a horizontal circular collision boundary:

1) If one cube runs into the back of another it stops (just what I need)
2) If one cube runs very close and parallel to another, it will stop as soon as its ellipsoid hits the other's box (not what I need - depending on the angle [90 degrees on is fine!])

Many thanks to b32 for the PreviewEntityRadius function, which helps illustrate my problem perfectly:



The sort of collision detection I am trying to achieve must be possible - but is unfortunately beyond my noob and limited understanding of 3D programming. Maybe I am trying to run before I can walk? :o/

If anyone can give me any pointers as to how else I can achieve this I would be extremely grateful.

PS: EntityRadius entity,x_radius,y_radius,z_radius please!


b32(Posted 2006) [#9]
I think you could use a physics library for this. I've never used one, but they were mentioned off and on here. Another solution might be turning your world 90 degrees, so the X is still X and the Y is the Z. That way the entityradius can remain upright, and still be adjusted to (sort of) fit the train.


Chalky(Posted 2006) [#10]
Hiya b32. I did try turning the objects 90 degrees but that didn't work. Mind you, I didn't turn the floor and camera as well (if that's what you mean?). Hmmm - I wonder...

[edit] Well - a couple of hours later, it doesn't work if I tilt the world either. :o( I give up. Think I might fire up dear old DBPro... ;o)


Stevie G(Posted 2006) [#11]
DB Pro? Have a bit of perseverance and you'll be rewarded!!

Parent 2 x collision pivots to your cube one at the front of the train and the other at the rear. Set sphere collisions to them, rather than the cube. For the cube, continue to set the entitypickmode but to polygon (2 I think ). This may work for you.

As far as I know box collisions do not rotate with the object it's applied to so it's not very useful imo.

I think you also need to get used to the blitz coords system otherwise you'll be in a world of pain later.

Stevie