Alice Community How do I constrain an object to not sink into the ground?

 How do I constrain an object to not sink into the ground?
 wpugh Guest   Status: Posts: n/a How do I constrain an object to not sink into the ground? - 04-13-2008, 08:59 PM I'm trying to create some simple tutorials with my kids. I'm creating something where an EvilNinja chases a bunny. The ninja moves towards tha bunny, and the bunny moves away from the ninja. What happens is that since the ninja is taller than the bunny, when the bunny moves away from the ninja it starts to sink underground. The Ninja follows it, and they both move ever downwards. Is there anyway to constrain the z positive of an object, or even to simply set the z coordinate of an object? While I'm at it, while there is way to have an object turn to face away from something?
DickBaldwin
Guest

Status:
Posts: n/a
04-13-2008, 11:16 PM

Quote:
 Originally Posted by wpugh I'm trying to create some simple tutorials with my kids. I'm creating something where an EvilNinja chases a bunny. The ninja moves towards tha bunny, and the bunny moves away from the ninja. What happens is that since the ninja is taller than the bunny, when the bunny moves away from the ninja it starts to sink underground. The Ninja follows it, and they both move ever downwards. Is there anyway to constrain the z positive of an object, or even to simply set the z coordinate of an object? While I'm at it, while there is way to have an object turn to face away from something?
The simple answer is yes, yes, and yes

Rather than to try to provide the details in this short space, I am simply going to refer you to http://www.dickbaldwin.com/tocalice.htm where I believe you will find the answers to your questions.

Dick Baldwin
Free Alice tutorials: http://www.dickbaldwin.com/tocalice.htm
Free programming tutorials: http://www.dickbaldwin.com/toc.htm

P.S.
Loop 5 times
Do together
evilNinja move amount = 2 meters toward target = bunny
bunny move amount = 2 meters away from target = evilNinja

Last edited by DickBaldwin; 04-13-2008 at 11:38 PM.

 Re: How do I constrain an object not to sink into the ground
 Quick thoughts
 DrJim Guest   Status: Posts: n/a Quick thoughts - 04-14-2008, 11:28 AM For staying above ground - just run the method inside a while statement with the test "while object is above ground." If you need to recover from going below ground, you can do that with a separate while "object's distance above ground is <=0" method. As far as tracking along a plane - the specific problem - the only way I know to do that easily is place a "not seen" object located at the target but at the same height above ground as the tracking object (bunny) and then make the dummy object the vehicle for the target and have it act as the effective target location for your code. For facing away, do the turn to face and then turn 1/2 revolution - but do both with zero second durations.
DickBaldwin
Guest

Status:
Posts: n/a
04-14-2008, 01:02 PM

Quote:
 Originally Posted by hgs I haven't run your code, but that sort of program has always resulted in unwanted changes of vertical position, in my experience.
Maybe I was asleep at the mouse, but the code that I provided appeared to run fine for me and I didn't see anything sinking into the ground. I will run it again just to make certain. The code is very short, so run it and tell me what you get. Be sure to use a bunny and an evil ninja. I believe that the key is the location of the center points on the two objects. In this case, the center point of both objects appears to be on the ground between their feet.

Thanks for the input.

Dick Baldwin
Free Alice tutorials: http://www.dickbaldwin.com/tocalice.htm
Free programming tutorials: http://www.dickbaldwin.com/toc.htm

 Object Center Points
 DrJim Guest   Status: Posts: n/a Object Center Points - 04-14-2008, 01:11 PM One of the real strengths of Alice is it's extensive library of objects which was developed by many contributors. Unfortunately, there was apparently no initial standard - and each of the contributors had their own idea as to where the "center" of an object should be - which can lead to interesting results. Having the center of an object end up in (very) strange locations is also a hazzard of importing your own objects. One suggestion if you are having problems is to view the objects with their axis showing.
 My solution to the quicksand problem
DickBaldwin
Guest

Status:
Posts: n/a
My solution to the quicksand problem - 04-14-2008, 02:27 PM

Quote:
 Originally Posted by hgs Dick, I don't think your answer addresses the question. I think you have just reproduced what wpugh is already doing. I have had this problem of characters walking into the ground before and as yet found no way around it. Google searches of your site don't throw up results that look like they address this issue. Maybe you can post a more specific link? I haven't run your code, but that sort of program has always resulted in unwanted changes of vertical position, in my experience....
I have attached my solution to the problem of the objects sinking into the ground during the chase. Please let me know if it doesn't work for you.

Properly setting the stage is critical in many Alice applications, and this is a good example of such an application.

See the following lessons on my website:

http://www.dickbaldwin.com/alice/Alice0115.htm
http://www.dickbaldwin.com/alice/Alice0120.htm

By the way, when I refer someone to my website, I don't always mean to imply that the exact answer to a specific question is provided there. Often I am simply indicating that if the person learns from the material that is provided there, they can usually answer their own questions.

Paraphrasing what a wise person once said:

Give a student a fish to eat and he will be hungry again tomorrow.
Teach him to fish and he will never be hungry.

Dick Baldwin
Free Alice tutorials: http://www.dickbaldwin.com/tocalice.htm
Free programming tutorials: http://www.dickbaldwin.com/toc.htm
Attached Files
 BunnyChase.a2w (900.4 KB, 144 views)

 A more detailed explanation of the cause of the problem
DickBaldwin
Guest

Status:
Posts: n/a
A more detailed explanation of the cause of the problem - 04-14-2008, 03:29 PM

Quote:
 Originally Posted by DrJim One of the real strengths of Alice is it's extensive library of objects which was developed by many contributors. Unfortunately, there was apparently no initial standard - and each of the contributors had their own idea as to where the "center" of an object should be - which can lead to interesting results. Having the center of an object end up in (very) strange locations is also a hazzard of importing your own objects. One suggestion if you are having problems is to view the objects with their axis showing.
To expand on what DrJim says above, the cause of the problem is explained in the section that begins as follows at http://www.dickbaldwin.com/alice/Ali...htm#moveToward

Begin quoted material =============================
The moveToward method

Recommended study trail: Return to the discussion of the method named moveTo.

Brief description: A method to cause an object to move a specified distance toward another object along an imaginary line that connects the center points of the two objects, without changing the orientation of either object. Also supports the asSeenBy parameter, which can complicate the behavior of the method.
=========================== End of quoted material

The methods named moveToward and moveAwayFrom behave essentially the same way with the main difference being the direction of motion. If you call either method without first assuring that the center of the two objects is at the same level relative to the ground, the line connecting the two centers will not be parallel to the ground, and the objects will either sink into the ground or fly away into the air depending on the direction of motion.

It is important that the programmer understands the behavior of a method before using that method in an Alice application. Otherwise, strange results may occur.

Unfortunately, CMU has not provided any information regarding method behavior except for their commercial textbook. You will find my description of the behavior of each of the primitive methods in Alice 2.0 at http://www.dickbaldwin.com/alice/Alice0900.htm While somewhat boring, this is probably the most important Alice material on my website. Note, however, that my interpretation of the behavior of each method is based on experimentation, and may not be correct in all cases.

If your Alice application doesn't behave according to your expectations, I strongly recommend that you consult that material and learn about the behavior of the methods that are called in your application. (When all else fails, read the instructions. It would actually be better if you learn about the behavior of each method before you use it.)

Dick Baldwin
Free Alice tutorials: http://www.dickbaldwin.com/tocalice.htm
Free programming tutorials: http://www.dickbaldwin.com/toc.htm

Last edited by DickBaldwin; 04-14-2008 at 03:31 PM. Reason: Correct grammar

 This is it
 Nickto1414 Guest   Status: Posts: n/a This is it - 08-02-2008, 06:02 PM Simpily While A<=B Distance above X Left Leg A=0 B=Ground X=Object You can get the A<=B in world -Functions
 debussybunny563 Senior Member     Status: Offline Posts: 852 Join Date: May 2010 10-01-2010, 08:35 PM There is a relatively simple method to solve this. 1. Add a dummy object to the world. Make sure it is upright/parallel to the ground (use the method "stand up" to ensure this). 2. Ninja turn to face bunny and move forward whatever amount. 3. Dummy move to ninja duration 0 seconds. 4. Dummy turn to face bunny duration 0 seconds. 5. Bunny move forward whatever amount asSeenBy dummy. 6. Repeat steps 2-6 however many times you want it to loop. Last edited by debussybunny563; 12-21-2012 at 12:00 AM. |--------------------------------------------------------------------------------------------------| |Link to weapons collection: http://www.alice.org/community/showthread.php?t=7368 | |--------------------------------------------------------------------------------------------------| I have been dead for quite some time now; not much hope for resurrection.

 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 BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements     Community News and Announcements Alice 3     How Do I?     Works In Progress     Share Your World     Share Custom Classes     Bugs and Trouble Shooting     Suggestion Box Alice 2     How do I...?     Works-In-Progress     Share Worlds     Share Objects     Bugs and Troubleshooting     Suggestion Box Educators     Teaching with Alice     Teaching Using Alice 3     Teaching Using Alice 2     CS Principles and Alice     AP CSA and Intro to Java and Alice     Workshops General Discussion     Questions and Comments     The Lounge