Alice Community

Alice Community (http://www.alice.org/community/index.php)
-   Works-In-Progress (http://www.alice.org/community/forumdisplay.php?f=14)
-   -   Collision Detection while walking (http://www.alice.org/community/showthread.php?t=3514)

BugMeNot 12-03-2009 04:09 PM

Collision Detection while walking
 
1 Attachment(s)
I am making an adventure-type game and have created a world. The game was working fine, except collision detection. He would simply walk through other objects. There are a few workarounds to this. The simplest one is the built in arrow-key control hit detection. If the camera is set to be controlled by arrow keys in the Events panel, the camera somehow automatically knows to not go through objects.

This would be perfect except by setting the person's vehicle to the camera, instead of moving forward from the person's perspective, it will move the person forward from the camera's perspective. The actual collision detection works great, except my character can no longer walk straight or even on a level angle (depending on camera angle).

Is there a way to use this built-in hit detection on other objects other than the camera? or, What is the best workaround for this situation?

x2495iiii 12-03-2009 04:14 PM

Short answer, no you can't. But you can make your own collision detection by using the "object is within x meters of object" function inside an infinity loop to constantly check to see if the character is touching an object (use object's width, another function, as the x value) and move that character away from the object.

Dameria wrote an early example of such a method, just search for collision detection and you should find it.

BugMeNot 12-03-2009 04:25 PM

I am aware of the other workarounds, there are just so many objects in the world (this is a very ambitious project) that it would take a lot of code to do that for every object. And some objects are buildings, and the camera's built in detection can go through doors and such while the width-threshold detection would not.

Besides, the camera's collision detection works perfectly and it's a little frustrating that this same concept cannot be applied to other objects.

x2495iiii 12-03-2009 04:41 PM

It is frustrating, but apparently it was difficult to include that one collision detection method in the first place. The reason there aren't built in methods is because there isn't one which would satisfy all needs.

Say you need use special effects in the form of billboards and smoke in your world. If those objects were recognized as obstacles by a detection method, it'd be impossible to walk through a puff of smoke (unrealistic). Conversely, if they weren't recognized, custom walls would be nearly impossible to create, as one of the easiest ways to make a simple, processor friendly wall is to import a billboard with a stone or brick texture. This is why it's easier to have the user decide which objects to collide with and which to pass through.

As for doors, I see 3 options:
-drop the character and go to first-person format
-make a sort of "auto enter" which checks to see if you're close to a door, then lets you enter automatically with a key press
-make a complex set of if/else ifs to see if the character is close to the door or the wall and act accordingly

Jeremytroid 12-03-2009 08:15 PM

1 Attachment(s)
Actually, it's quite simple.:p

Just do an "if/else" method set to 'character'. Then do "if 'character' is within 1 meter of 'object' move backward 1 meter" Else, do nothing.(click the character in the object branch and click "new method" then put the latter series of code)You only have to do this once and all objects should be solid.

I have a Mac and collision detection never works. So somebody try tell me if it works. It should work on PC. It does in my Mirror's Edge game.

x2495iiii 12-04-2009 12:04 AM

Jtroid, your world didn't seem to work. It looks like the distance isn't large enough and the time it moves backward should be zero seconds and should only activate if the mole is moving forward (if it's moving backward, then it'll warp right into the fun house).

reuben2011 12-11-2009 03:47 PM

To have collision detection for multiple objects you can always make a list of all the objects (call it something like dontCollideWith). Then make a for all together and use item_from_[array] as the objects when using the object is within [x] meters of object. Then as the distance, use item_from_[array]'s width or depth.


All times are GMT -5. The time now is 01:59 PM.

Copyright ©2021, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.