How To Have A Camera Follow A Set Path Unity
- Spaces
- Default
- Help Room
- META
- Moderators
-
- Topics
- Questions
- Users
- Badges
- Home /
2
How to brand object follow path?
Hey I'm a noob here and I need assistance making my object follow a path. I've used waypoints and the nav broil role but none of them are working. I'five looked all around so and link you'll ship me I would've probably already look through.
The problem with this script is that the thing that I want to follow the path doesn'east even move. In fact, nothing at all happens and I have no idea why.
This is my code if you were wondering:
using UnityEngine; using System.Collections;
public class WayPoints : MonoBehaviour {
public Transform[] wayPoint = new Transform[9]; int currentWayPoint = i; public float rotationSpeed = 6.0f; public float acceleration = 1.8f; // Use this for initialization void Start () { wayPoint [0] = GameObject.Notice ("WayPoint1").transform; wayPoint [1] = GameObject.Find ("WayPoint2").transform; wayPoint [2] = GameObject.Find ("WayPoint3").transform; wayPoint [three] = GameObject.Find ("WayPoint4").transform; wayPoint [four] = GameObject.Find ("WayPoint5").transform; wayPoint [5] = GameObject.Find ("WayPoint6").transform; wayPoint [6] = GameObject.Discover ("WayPoint7").transform; wayPoint [vii] = GameObject.Observe ("WayPoint8").transform; wayPoint [8] = GameObject.Find ("WayPoint9").transform; } // Update is chosen once per frame void Update () { if (currentWayPoint == ix) { Destroy (this.gameObject); Histrion.lives =- 1; } else {
// walk(); } }
void walk(){ Quaternion rotation = Quaternion.LookRotation (wayPoint [currentWayPoint].position - transform.position); transform.rotation = Quaternion.Slerp (transform.rotation, rotation, Fourth dimension.deltaTime * rotationSpeed); Vector2 wayPointDirection = wayPoint[currentWayPoint].position - transform.position; bladder speedElement = Vector2.Dot(wayPointDirection.normalized, transform.forward); float speed = acceleration * speedElement; transform.Translate (0, 0, Time.deltaTime * speed); } void onTriggerEnter(Collider collider){ if (collider.tag == "WayPoint") { currentWayPoint ++ ; } }
}
thx for your time!
2 Replies
· Add together your reply
- Sort:
11
Answer by sansol · Jun 29, 2015 at 03:55 PM
hi , i don't know if y'all are still looking for an answer, but since i had the same problem and found a solution to information technology, i mail service information technology here for future reference.
lawmaking here:
public course WayPoints : MonoBehaviour { // put the points from unity interface public Transform[] wayPointList; public int currentWayPoint = 0; Transform targetWayPoint; public float speed = 4f; // Use this for initialization void First () { } // Update is chosen once per frame void Update () { // check if we have somewere to walk if(currentWayPoint < this.wayPointList.Length) { if(targetWayPoint == null) targetWayPoint = wayPointList[currentWayPoint]; walk(); } } void walk(){ // rotate towards the target transform.forward = Vector3.RotateTowards(transform.forward, targetWayPoint.position - transform.position, speed*Time.deltaTime, 0.0f); // move towards the target transform.position = Vector3.MoveTowards(transform.position, targetWayPoint.position, speed*Fourth dimension.deltaTime); if(transform.position == targetWayPoint.position) { currentWayPoint ++ ; targetWayPoint = wayPointList[currentWayPoint]; } } }
Hello, Thank you, This script solved some of my bug but I need some help. I am using it in a Plane and then the plane will follow the wayPoint. In fact the plane follow the path but for some reason // rotate towards the target transform.forrard = Vector3.RotateTowards(transform.forward, targetWayPoint.position - transform.position, speed*Time.deltaTime, 0.0f);
Rotate the Plane and the plane follow the path with the tail pointing to the WayPoint. So the plane is flying contrary. The Mode Signal and the Plane has the Axes in the same direction. I remember it has to be something with the Word coordinates. Is it any way to correct this? Thank you very much for any help or support.
Then i'm new here, dont know if you lot were able to solve your trouble... what I would do is open up your model in $$anonymous$$aya (or something) and rotate it 180 ° (and freeze transforms - del history).
Recall this would exist the simplest fix. Cheers
Howdy, i`one thousand getting ArrayOutOfIndex exception here. Whatever idea?
How-do-you-do I am too new to unity i have a question involving your solution. is the solution a complete program or a $$anonymous$$or script change. if i know this i could brand a zombie horde game. please reply as soon as yous can i would be grateful to know this. cheers.
sincerely SENIORFUZZYHEAD.
hey , i have alot enemy that i wanna take a simple motility to correct and back to left again and again .i know i tin can employ points and objects for everyone of them to make a path and do this but is in that location anyhow only with codes tin can do this ? (without whatever new object ) like this ....
transform a ; a =new vector2(gameobject.transform.position.ten +3f ,gameObject.transform.position.y); b=new vector2(gameobject.transform.position.x -3f ,gameObject.transform.position.y); transform.position = Vector2.$$bearding$$oveTowards(gameObject.transform.position, a.transform.position, movespeed * Time.deltaTime); if (gameObject.transform.position.ten == a.transform.position.x) transform.position = Vector2.$$bearding$$oveTowards(a.transform.position, b.transform.position, movespeed * Time.deltaTime); if (gameObject.transform.position.x == b.transform.position.x) transform.position = Vector2.$$bearding$$oveTowards(b.transform.position, a.transform.position, movespeed * Fourth dimension.deltaTime);
already i did this simply didnt work....
0
Answer past gOzaru84 · Dec 13, 2018 at 11:06 AM
Your answer
Follow this Question
Related Questions
Source: https://answers.unity.com/questions/894796/how-to-make-object-follow-path.html
Posted by: schultzplefuspritir.blogspot.com
endeavour changing transform.Translate(...) to..
thx but it nonetheless doesn't work. Goose egg happens, the enemy doesnt movement. If anyone tin can assistance, please do.
No errors in the console of whatsoever kind? Or the enemy simply doesn't movement at all? I may be wrong hither, but this:
seems to be telling the enemy to move 0 on the x, 0 on the y, and then telling it how FAST to move on the Z, simply not telling how FAR to move on the Z. If I am wrong I am sorry, it's just the way it looks to me.