Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

testing for a collision ahead of time

Discussion in 'Scripting' started by spiralgear, Dec 19, 2007.

  1. spiralgear

    spiralgear

    Joined:
    Dec 13, 2007
    Posts:
    528
    Is there anyway to check the terrain in front of an object for slope limit and step offset with out actually having an object try to move over it



    im trying to make an AI car use this information to decide which path is less bumpy on a mesh that is constantly being deformed by player input




    right now i have an invisible object with similar attributes move along the path ahead of it and sends back a message if it is stopped, but this is very inefficient because it takes a long time for it to "think" about the path because it has to wait for the object to actually travel to the end of the test space before it knows the answer


    but i really have no idea where to start,some one want to point me in the right direction??
     
  2. Marc

    Marc

    Joined:
    Oct 4, 2007
    Posts:
    499
    I would let the object moving shoot Rays and hit test the rays intersection with the world.
     
  3. spiralgear

    spiralgear

    Joined:
    Dec 13, 2007
    Posts:
    528
    im sorry im still kind of new to unity, would you mind going into a bit more detail



    do you mean the moving object shoots rays down to collect collider information? If so how do i store that information?
     
  4. pete

    pete

    Joined:
    Jul 21, 2005
    Posts:
    1,647
    http://unity3d.com/support/documentation/ScriptReference/Physics.Raycast.html?from=RaycastHit

    you can only set the slope limit and step offset for the character controller iirc. so that probably won't help you. for finding the slope of the hit point you'd want to get the poly's normal using something like Physics.RaycastHit.normal and compare its vector. Physics.Linecast might work for you too.

    can't remember but there also might be some obstacle avoidance in the ai (robots) scripts in the fps sample.