- Home /
Using raycast to move on uneven terrain with iTween Path
Hello coders! I have been looking around all day trying to figure out how to use raycasting to move an object on uneven terrain. I am rather new to this so bare with me.
What i got: An object that moves along a path created with iTween path. Terrain with a small hill in the iTween path.
What i am trying to do: Get the object to move over the hill insted of clipping through it.
I have a basic raycast code that detects the ground:
function Update () {
var up = transform.TransformDirection(Vector3.up);
Debug.DrawRay(transform.position, -up * 1, Color.red);
if(Physics.Raycast(transform.position, -up, 1)){
Debug.Log("Hit");
}
I have seen this link: http://answers.unity3d.com/questions/168097/orient-vehicle-to-ground-normal.html
As i code in Javascript, im having trouble understanding that link.
Any help would be much appriciated!
Here is the code to make an object move on a path with iTween path. The object also rotate along the path, and loop back and forth on the path. (The object doesn't spin around when it moves back along the path, im working on fixing this) Hope this helps anyone.
void Start () {
iTween.MoveTo(gameObject, iTween.Hash("path", iTweenPath.GetPath("test"),"looptype",iTween.LoopType.pingPong, "orientToPath",true, "lookTime", 0.2, "time", 10,"easetype", iTween.EaseType.easeInOutSine));
}
Thanks!
Your answer
Follow this Question
Related Questions
Have object follow mouse on terrain 1 Answer
Instantiated Objects not being set at ground/terrain level?(Solved) 1 Answer
Raycast problem trough the terrain 1 Answer
what is the easiest way to do a moving car on uneven terrain 1 Answer
How to determine what points on terrain can be seen from a certain point? 1 Answer