View Full Version : collision check how? help thanks
grandstream
06-10-2006, 12:18 PM
I'm doing a collision check for my alice project. Prevents the object to run into the maze.
Currently, my script is
http://img.photobucket.com/albums/v111/grandstream/collisioncheck.jpg
but i can't get it to work, help please thanks in advance.
Jabberwocky
06-10-2006, 12:31 PM
Less than zero? Try distance to hedge less than 1 instead.
grandstream
06-10-2006, 12:32 PM
tried that too.. the object just go through thanks anyway
Jabberwocky
06-10-2006, 12:38 PM
collision detection (http://www.alice.org/community/showpost.php?p=614&postcount=2)
grandstream
06-10-2006, 12:54 PM
collision detection (http://www.alice.org/community/showpost.php?p=614&postcount=2)
sorry for asking stupid question without searching. thanks again
Jabberwocky
06-10-2006, 01:41 PM
No problem... collision is tricky. If you set the arrow keys to control the camera you won't walk through objects. (Make sure your line of sight is in line with the object though; if you can see over the hedge you'll just walk right through.)
Achieving a third person perspective, above and behind fatherRabbbit, so you can watch him move through the maze, will require a lot of the work. You'd have to do a lot of proximity checking; for each wall of the maze.... but I'd think that would be a problem as the maze is one big object with no sub-parts.
Perhaps you could either build your own maze with individual walls, or place invisible objects in front of the walls and proximity check against them.
Fun, fun! ;)
grandstream
06-10-2006, 02:16 PM
No problem... collision is tricky. If you set the arrow keys to control the camera you won't walk through objects. (Make sure your line of sight is in line with the object though; if you can see over the hedge you'll just walk right through.)
Achieving a third person perspective, above and behind fatherRabbbit, so you can watch him move through the maze, will require a lot of the work. You'd have to do a lot of proximity checking; for each wall of the maze.... but I'd think that would be a problem as the maze is one big object with no sub-parts. Walking inside the maze your proximity becomes like what you were trying to achieve less than zero .
Perhaps you could either build your own maze with individual walls, or place invisible objects in front of the walls and proximity check against them.
Fun, fun! ;)
thanks again, will try to place invisible objects along the walls of maze.
grandstream
06-10-2006, 02:45 PM
i tried to insert "invisible" items into the blocks of maze. The inflexibility of alice is the "distance to" is measured from centre of the item to the other's . As a result, i can't simply insert one string of long text... It will still be measured by the centre of point.
If i insert so many items inorder to fit them into my big maze... OMG, the file size would be so big and the numbers of item to test for collision is so much to more. Imagined "if nested if if if if if" with the amount of objects ..the numbers of if would be unbearable. I haven't have the chance to test if making a list of those object would work.
Kinda stuck now, gonna sleep first and try again tommorrow.
Jabberwocky
06-12-2006, 11:13 PM
Using the "distance to" command, Alice measures from the center of an object on all 3 axes (x, y, & z). Checking for less than zero doesn't work because the distance between two objects is always positive, depending on your point of spatial reference.
The square is the simpliest object I see in the shapes folder, it's only 2k. HedgeMaze3 is 468k. You could use 234 squares and just match the size of the maze. World size shouldn't be a problem. Regardless of the size of the barrier segments, you'd definately want a list to store the barriers in.
The example world, Flight Simulator, checks for a ground collision by checking if "distance above object < 0". Checking for less than zero is appropriate here. "Distance above" is related to one coordinate plane, height, anywhere you cross (in x or z plane) triggers the event. "Distance in front of" works like the "distance above" command.
If you use "distance in front < 0", with any sized object, and cross to the negative side (-z) you would trigger it no matter where you were on the x & y planes. The problem is the maze folds back on itself. If you check "distance in front of" on one pathway and then walk around to the back following the maze, you'd be behind the object on another legitimate pathway but triggering the function from the opposite side.
You should check into the other proximity commands and maybe even the spatial ones. Perhaps a combination might do the trick. Let me know if you find a solution.
Good luck!
Jabberwocky
06-13-2006, 05:08 PM
For an excellent example of collision detection check out the racing game (http://www.alice.org/community/showpost.php?p=130&postcount=1) by crazychimp132.
I was thinking you'd need to use the "while key is pressed" routines so you could stop the rabbit from walking, and avoid the user just barreling through a wall. As well as set up indicators as to what pathway you were on like the checkpoints, and set up something for spatial orientation like the axes here.
Nice!
lanceA
06-13-2006, 07:34 PM
The textbook also has a great example, Bumper Cars, from Chpt 7 Exercises. However in lieu of using the .distanceTo() function the cars can be kept from driving through each other using the .iscloseTo() function.
And yes it does take a few If-statements to accomplish, but isn't that what coding is all about? ;) You could write a world-level method for the If-statements, pass your Object as a paramter, and return a boolean.
madden
03-24-2007, 12:21 AM
thanks again, will try to place invisible objects along the walls of maze.
lets make a tower:D