Alice Community (http://www.alice.org/community/index.php)
-   How Do I? (http://www.alice.org/community/forumdisplay.php?f=28)
-   -   Stop MoveForward and rotate by angle (http://www.alice.org/community/showthread.php?t=12278)

 Rosky 05-25-2021 03:25 AM

Stop MoveForward and rotate by angle

Summary of what i can't find how to do:

1. StopMovingForward with CollisionDetection
2. RotateBy random angle
3. Bounce back

The project i want to do:

Want to make 5 meteorites with random sizes and random rotation fall to the ground. This means that the distance to collision with 'Ground' is unknown and the moveforward distance i have to set must be big.
When any falling meteorite hits the ground should stop moving and bounce back (preferably but not necessarly in a sine wave).
Colision detection works but how do i stop the [U]meteorite MoveForward[/U] from going trough the 'Ground'? After stopping i want to change direction (rotate it) and move it away from ground.

Stoping it should be something simple but i don't seem to be able to find out how.
Thank You.

 djslater107 05-25-2021 10:11 AM

Meteorite collision with ground

1 Attachment(s)
Without know the details of how you are implementing the meteorite motion, I have attached a very simple program in which a boulder "falls" to the moon surface, and when the collision happens, a changeDirection method is called that reorients the boulder to a new, random, direction.

In my program, my boulder would always be moving in a separate procedure, the collision detection just changes the direction it is moving.

To make the boulder stay on the ground, I created a Boolean variable for the Boulder class, canBounce and initialized into true. In myFirstMethod, my while loop checks this variable to see if it can continue moving or not. In my CollisionDetector, I Set this variable to false to stop the while loop.

(Also in the CollisionDetector I enabled / disabled the changeDirection procedure or the meeting the Boolean variable to false so you could see either option.)

I hope this helps.

 All times are GMT -5. The time now is 06:26 PM.