Collision Situation

Blitz3D Forums/Blitz3D Beginners Area/Collision Situation

YellBellzDotCom(Posted 2007) [#1]
I have a tree with like 100 polys, and set up collision properly...

OakTree = loadmesh("C:\OakTree.b3d")
PositionEntity OakTree,80,10,20
ScaleEntity OakTree,.1,.1,.1
EntityPickMode OakTree,2
NameEntity OakTree,"Oak Tree"
EntityRadius OakTree,5
EntityType OakTree,Type_Scenery

Sphere16 = loadmesh("C:\Sphere16.b3d")
PositionEntity Sphere16,20,10,20
Scaleentity Sphere16,.5,.5,.5
EntityPickMode Sphere16,2
EntityRadius Sphere16,5
EntityType Sphere16,Type_Scenery
NameEntity Sphere16,"Oak Tree"

Circ = CreateSphere(8)
PositionEntity Circ,40,10,40
ScaleEntity Circ,5,5,5
EntityPickMode Circ,2
EntityRadius Circ,5
EntityType Circ,Type_Scenery
NameEntity Circ, "Circ"

Play1 = CreateSphere()
ScaleEntity Play1,2,2,2
EntityPickMode Play1,2
NameEntity Play1,"JoeJoe"
EntityRadius Play1,2
EntityType Play1,Type_Char

Collisions Type_Char,Type_Ground,2,3
Collisions Type_Char,Type_Scenery,1,2

While Not KeyHit(1)

     CheckMouse() ;Checks for mouseclicks

     MoveEntity Play1,0,-1,0

     UpdateWorld()
     Renderworld()

     Flip
Wend
ClearWorld()
End



The problem is the Play1 will not slide around the oak tree b3d model or the sphere16 model, but will slide around the Blitz created sphere properly. I also created a Sphere with 8 segments so I could have a lower poly sphere mesh and see if it was the smoothness of the mesh that was causing the play1 to "Stick" to a mesh when a collision happened, but it didnt matter.

The question is, what am I doing wrong here. Based on this code the play1 mesh should slide around any of these objects when it collides, instead it slides around the blitz created mesh but not the loaded meshs.

Any help would be greatly appreciated!

Thank you.


Ross C(Posted 2007) [#2]
You seem to be giving the tree an entity raduis. But, your using it for colliding against. I assume your tree must be round or something. Just an odd collision response to have for a tree :o)

What might be happening is your model's scale isn't going to be 1,1,1 be default. You should compare the models against blitz created meshes, to get an idea if the scales are the same. Since your scaling the meshes, the meshes might be alot bigger than your EntityRadius.

Try sphere to poly responses, and see what happens.


Terry B.(Posted 2007) [#3]
Yes seems like your Radius is too big.
This is a function to show the radius of an entity someone gave me a while back.

Function PreviewEntityRadius(mesh, xz_radius#, y_radius#)
	EntityRadius mesh, xz_radius#, y_radius#
	sphere = CreateSphere()
	ScaleEntity sphere, xz_radius#, y_radius#, xz_radius#
	EntityAlpha sphere, 0.5
	EntityParent sphere, mesh
	EntityColor sphere,0,0,0
	RotateEntity sphere, 0, 0, 0, 1
	PositionEntity sphere,0,0,0
	Return(Sphere)
End Function


So paste this into your code (after the end) and try PreviewEntityRadius(Tree,5,5) Instead of Entityradius Tree,5


YellBellzDotCom(Posted 2007) [#4]
Wow, nice function there Terry R. I do appreciate the help here. Im not really convinced theres a difference between Blitz Created mesh and loaded ones, it just may have looked like the collision worked better on Blitz Meshes. No matter how big, or how small I make the entityradius, and unscale my meshes, adjust the radius command, the character sticks to the objects instead of sliding. Ill see if I can make a vid showing this...

Terry R - "Yes seems like your Radius is too big."
In Reality, would it matter how big the collision radius is? If I have a Cone thats 10 units wide and I create a collision radius 40 units wide, wouldnt the character stop and slide way before he visually ran into the tree? Isnt that what the entityradius command is for?

Ross C - "Since your scaling the meshes, the meshes might be alot bigger than your EntityRadius."
Would this interfere with collision if it was the case? Only on Ellipsoid to Poly collision I would imagine, in which case I wouldnt be using a Radius collision. The Character would just walk into the mesh before a collision would be detected, then if response = 2 it should slide around the collision radius. I wouldve thunk anyways.

Maybe I'm missing something here thats pretty critical, but I thought that if you use method1, ellipsoid to Ellipsoid, you need to use Radius command to define the Collision bubble around objects. When those collision bubbles come into contact and you have a response of 2, sliding, then source object should slide around the dest object.

Thanks again for you help.


YellBellzDotCom(Posted 2007) [#5]
Ok, heres a video showing the my problem, sliding does occur but not at the level I would like. If you click for the character to walk and he encounters an object. I wanted him to slide either left or right to get around the object. It just doesnt seem right that he sticks to the object at all.

The little gray bubbles are the PreviewEntityRadius Results...
http://s195.photobucket.com/albums/z47/Xyled777/?action=view&current=WTWMPV1212-9-07.flv

Thanks again


Terry B.(Posted 2007) [#6]
Alright after the vid I see your problem.

You want you to be able to slide around the trees?

I think, that instead of this
Collisions Type_Char,Type_Scenery,1,2

try Making it slide2
or this
Collisions Type_Char,Type_Scenery,1,3



YellBellzDotCom(Posted 2007) [#7]
Yeah, Ive tried it all ways I possibly could, method 1 and response 3 gives the same exact situation.

I believe, in order to continue I will have to institute a grid system with pathfinding, hehehe. Cya in 2 years, lol.

I really appreciate the help.


Stevie G(Posted 2007) [#8]
Moving the character by a fraction of the collision normals MAY improve this ..

for c = 1 to countcollisions( player )
translateentity player, collisionnx( player, c ) * .1, collisionny( player, c ) * .1, collisionnz( player, c ) * .1
next

Stevie


IPete2(Posted 2007) [#9]
Hiya,

Just a thought - this may be over kill but it depends on what you want to happen - if all your trees are round and have different radii you can forget Blitz's collisions and do the following:

(1) Identify which tree your character has hit and then by using maths to find the radius of an invisible circle around your character and the radius of the tree (this can also allow you to see if they have collided).

(2) Now you know which tree it is, and you know what the radius is, you can position and then move your character at the edge of a circle defined by using the radius and Pii of that tree.

The routine would only be called whilst you are colliding with the tree. You can adapt the function in the code archives which determines which is the shortest path to your cursor and go either anticolockwise or clockwise based on that result.

If I can find the correct bits of equations I'll post them but I think you'll know what I mean - just think of it in 2D viewed from above.

Better explanation:
Two circles are positioned on a 2d screen one is the trees collision boundary and one is the players character collision boundary. If the distance from the centre of these objects is less than their individual radii added together then the maths proves that they have collided.

If the distance is 3 units and their radii added together is 2 there is no collision. If their radii added together is greater than 3 then they are colliding. Now you know they are colliding you can use the tree radius to calculate a cirlce and plot a path for the character to slide around.

So now you know they have collided which way around the tree is the shortest route to your cursor? Use the shortest path function fond in the code archives to determine which way to go. Now use the circumferance of the tree to position your character on the edge of the collision circle (based on the tress radius).

IPete2.


YellBellzDotCom(Posted 2007) [#10]
IPete2, thank you for the effort and the help. I thought that blitz collision commands already did all this. I thought setting up a simple collision system using the commands would have taken care of character and tree collision and force the character to slide around the tree. Since collisions arent working at such an early state, I am being forced to go into the pathfinding direction. I think deep down, I knew I would have to go this route, but was trying to avoid it, hehehe.

Your idea, I believe, would work without any problems and I may revisit this in the future. The thing about pathfinding is it will solve and take care of more situations than just the collision.

Thank you for the help.