PDA

View Full Version : How do i do the collision detection code?


xyflz
11-01-2009, 05:55 PM
Hi im making an object runing behind another object. when i last object catch up the front object, i want him to turn and pass the front object. How can i make this possible? thanks a lot

ps: i tried the distance function with if and else statement but its not working. object is still going through another.

x2495iiii
11-01-2009, 06:38 PM
Odds are, the if/else if statment needs to be put into an infinity loop, then put into a do together method along with the method to make the character move. This way, the world will be constantly checking to see if the character is close enough to the object to collide with it.

xyflz
11-01-2009, 08:45 PM
i think i did that but i will check it again. thanks for tip

xyflz
11-01-2009, 08:47 PM
yea thats what i did but its still not working. can you check it for me please?

xyflz
11-01-2009, 08:55 PM
btw. when i use a method. how can i just remove the duration part without removing the whole method?

x2495iiii
11-01-2009, 09:11 PM
You can't. If you change it, it'll stay there forever unless you delete it and re-insert it. It's one second by default, though, so if you want to change it to the default, change it to 1 second.

I'm taking a look at the world right now.

xyflz
11-01-2009, 09:14 PM
ok no wonder it wont let me do anything. yea when the chicken pass the turtle, chicken should run around the the turtle and talk. However,its not working at all.
your video on youtube is awesome i like it lol.

x2495iiii
11-01-2009, 09:21 PM
Nope, you put the collision detection method INSIDE the loop, not next to it in it's own loop inside the main do together method.

Put the if/else if statement in it's own, seperate loop, outside the chicken's motion method, and it'll work.

xyflz
11-01-2009, 09:28 PM
ok i see. im trying to make the them going around another when they pass the slower object. how do i make that work?

x2495iiii
11-01-2009, 09:53 PM
The way the world is now, you can't. You'll have to change the movement methods to something like:

"While (animal) is at least .05 meters away from beach chair 1"
(animal) move forward .03 meters duration 0 seconds.

With the move to methods, each animal is locked on a linear path to each chair, unable to move to the side.

xyflz
11-01-2009, 09:59 PM
i cant make the animal goes around another although i can make them detecting the collision

x2495iiii
11-01-2009, 11:51 PM
What do you mean? Did you change the movement method already?

xyflz
11-02-2009, 07:37 PM
yea i changed the method to "move toward" but i cant make them change direction as they detect another animal on their way.

Darkstar
11-16-2009, 12:11 PM
Odds are, the if/else if statment needs to be put into an infinity loop, then put into a do together method along with the method to make the character move. This way, the world will be constantly checking to see if the character is close enough to the object to collide with it.

I need help on this too. Im making a race car game for class and i need the car to stay on the road so i wanted to make a barrier on the side of the road and every time the car got within a certain distance of the barrier it moves over. But how are you supposed to put a loop in the if statement it wont let you? please help

kylefwlr
11-16-2009, 06:07 PM
can you add turns to your animal movements to turn, move so far forward, then turn back and keep going forward, turning back if they're headed to the same place you can use an orient to(slower animal) also i think, kinda new to alice too so just a thought

dubastot
11-18-2009, 08:02 PM
I need help on this too. Im making a race car game for class and i need the car to stay on the road so i wanted to make a barrier on the side of the road and every time the car got within a certain distance of the barrier it moves over. But how are you supposed to put a loop in the if statement it wont let you? please help

You don't put a loop in the if statement. There are two options. One is you can make an infinity loop and put the if statement into that( drag and drop the if statement into the infinity loop). Or you can have a while the world is running event. Just make your if method and put it in the during section of the while the world is running statement.