 |
|
|
|
|
 |
|
|
Guest
|
How do I not walk thru walls? -
02-03-2006, 01:37 PM
Ive been messin around in Alice over the past few weeks. I'm taking an Independent study course and I'm trying to figure somethings out. Main question is, how do I make it so I dont walk thru walls and stuff. Ive looked at some tutorials and tried countless things but I cant seem to just bounce of or be stopped by a wall. Can anyone help me out?
|
|
|
|
|
Administrator
Status: Offline
Posts: 461
Join Date: Jul 2005
Location: Pittsburgh, PA
|

02-06-2006, 11:36 AM
What you are looking for is collision detection, which is not implemented in Alice 2.0. There is no easy way to do this, apart from trial and error.
Here are some other posts on the subject:
http://www.alice.org/community/search.php?searchid=6546
|
|
|
|
|
Guest
|

04-07-2006, 02:59 PM
Well crap... We are doing this as an independant study and our instructors only criteria he wanted us to accomplish was to find out how to not walk thru walls...
|
|
|
|
|
Guest
|

04-07-2006, 08:25 PM
gabe appears to be correct when he states "...there is no easy way to do this...". I just received my copy of Charles Herbert's "An Introduction to Programming Using Alice" and he even admits that it "...is rather time consuming;" (pg 146)and then he continues with "...as such, it is not part of this tutorial."
But it can be done ?
Last edited by lanceA; 04-07-2006 at 08:39 PM.
|
|
|
|
|
Guest
|
well its not a total solution... -
11-27-2006, 02:49 AM
but there is another way to test for collisions: the math
-boxes collide if the distance between them in all axes (forward, left, above) is less than the sum of half their widths in each of those dimensions) - (b.depth_as_seen_by_x + a.depth_as_seen_by_x) <= (a.forward_distance_to_x) and (b.width ... ) and (b.length ...). as for handling collisions, perhaps you can try the left,forward, down or whatever its called function of world to revert to an earlier position, or you could use a dummy object infront of the avatar that you perform the collision detection on (note that you'd need another for backing up) - this way the person "hits" the wall before the intersect it. alternatively, if you are willing to sacrifice free user movement, you could represent the maze as a 2d array of tiles, with each tile either being passable or not, as an array, and just let the user move forward if the destination element - since alice doesn't support two-dimensional arrays, you need to use a scheme like element index of (x,y) = x * mazew + y. (note that this will be a maintance nightmare if you want to edit/resize the maze though!)
also, the formula for sphere-sphere collision is if the sum of the radii is less than or equal to their distance. cube to circle is similar, but you have to find the "closest point" on the cube(constrain the x,y,z values to 1/2 width ,height, or depth, until you get the closest point). note that these solutions don't work so well if you have objects that aren't upright.
finally, if you really need to add collision detection natively to alice, you might want to program it in, in java. (this is probably the most timeconsuming of my suggestions, but if you are taking an independent study course, then you have plenty of time right?). anyways, what i'd recommend for that is to add a world function that takes two objects, and returns a boolean if they collide, and use java to implement that functionality. also, you'd probably want it to check the objects parts against the whole other object (or maybe just its parts), but be careful about that one, since if you're not careful, you might end up with an n^2 implementation.
actually, looking at the source i'm surprised to find the following file
"edu.cmu.cs.stage3.alice.core.question.IsColliding With". i'm not sure if this file implements what you are looking for, but based on a cursory look at the source code and based on the name, i beleive this is what what you are looking for. now all you probably need to do is to mod the editor to allow you to put this in (maybe you could even manually edit an object to have a question of this type in a function and then just import that object into a world and use that function(which if it works - i haven't looked at the alice file loading code to see if it uses a factory or the java.lang.reflection api when instantiating objects), would allow a compatible solution.
|
|
|
|
|
Administrator
Status: Offline
Posts: 461
Join Date: Jul 2005
Location: Pittsburgh, PA
|

11-27-2006, 10:27 AM
Collision detection was a feature that never finished development due to inconsistencies between models. There are trace bits of code, but nothing complete.
|
|
|
|
|
Guest
|

11-27-2006, 12:58 PM
i was wondering why they didn't add simple collision detection though (ie - [obj] world.getThingsCollidingWith(object source, (enum) collisionPrimitiveToUse = BOUNDING_CUBES), that returns a list of objects that collide with it (Based on the primitive specified), or even a simple "does cube collide with cube" test? it doesn't seem that difficult to do in java, but its truely annoying to do in alice. (esp. since its not really possible without a lot of hacks to get the orientation of an object (you'd need to place something in front of it with a vehicle to the thing) then use trig to find the angles, for true 3d collision testing, where as in java, you could probably just have the function solve the equations.)(another problem is its troublesome to get a limb's own dimensions, not the combination of it and its sublimbs' dimensions, which makes other forms of collision testing difficult in alice). i guess i wish the following existed:
1. [Object].getMyCoord(Direction) - returns the absolute coordinates of an object relative to the world(center to center) on that direction's axis(this one isn't to hard i suppose)(in meters)
2. [Object].getMyAbsoluteAngle(Direction) - returns one of three component angles (yaw, pitch, roll) which determine the object's orientation(in Rotations)
3. (the ability to use positions and orientations as simple data types - ie:
[Position] myPosition = {0, 0, 0}
[Position] myTranslation = firstObject.offsetFrom(secondObject);
myTranslation = myTranslation.getUnitVector();
myPosition.place(myObject, 0 seconds);
myPosition.move(myTranslation, 0 seconds);
PointOfView testPosition = {{0,0,0},{0,0,0}};
pointOfView.pointAt(myTranslation, 0 seconds);
testPosition.place(myPosition, 0 seconds);
boolean bAcceptMove = false;
for all in (world.solidObjects), on at a time
{bAcceptMove = bAcceptMove or world.collisionTest(testPosition, myObject3.getCollisionPrimitive(BOUNDING_CUBE), item_from_solidObjects.getPointOfView(), item_from_solidObjects.getCollisionPrimitive(BOUND ING_CUBE));
}
if (bAcceptMove)
{
myObject3.setPosition(myPosition, 1 second);
}
else
{
//move fails.
}
... or something.
of course, a function that returned a position object that was a translation of an object along that object's local coordinate system could help too, as would a function to get its actual total movement per second(ie the sum of all move's and such that are currently affecting it)
anyways, if we developed a feature like this and manage to get to to work in alice2 could we submit it on the hope that you people might eventually make an update to alice that included these functions? i'd code some of this stuff, but i have no incentive to do so if all i do is render my copy of alice incompatible with everyone elses.
|
|
|
|
|
Guest
|

09-05-2007, 08:09 AM
For the collision detection in my first person view adventure game, I calculate the distance to a wall, and my move method stops when my dummy(used for movement) gets within a certain threshold. I use different values for different objects, to help with realism. It IS a bit of extra code, but once it is done, you can pretty much copy paste it to each object receiving collision data. For example, I have a gate that I don't want anyone going thru, until they've hit a switch that opens the gate.
if (dummy.iscloseto (3 meters, gate))
and then it sets my movement flag to 0, turning off movement in whichever direction. Not perfect, but functional.
This method is dependent on frame rate, so it is possible that you can still go through a wall if your machine isn't rendering very fast. You can tweak movement speed and threshold distance to strike a good balance.
|
|
|
|
|
Guest
|

09-05-2007, 04:04 PM
Quote:
Originally Posted by ShaunHBGAcad
For the collision detection in my first person view adventure game, I calculate the distance to a wall, and my move method stops when my dummy(used for movement) gets within a certain threshold. I use different values for different objects, to help with realism. It IS a bit of extra code, but once it is done, you can pretty much copy paste it to each object receiving collision data. For example, I have a gate that I don't want anyone going thru, until they've hit a switch that opens the gate.
if (dummy.iscloseto (3 meters, gate))
and then it sets my movement flag to 0, turning off movement in whichever direction. Not perfect, but functional.
This method is dependent on frame rate, so it is possible that you can still go through a wall if your machine isn't rendering very fast. You can tweak movement speed and threshold distance to strike a good balance.
|
nice solution!!!
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Copyright ©2023, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.
|
 |