Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Bitcore · Feb 10, 2020 at 01:35 PM · followfollow playertrailrenderertrail rendererfollow path

Use trail renderer for path following?

Hey guys, I'm pretty new to C# and still am learning the basics. Would really appreciate some guidance. Had this idea of flying opponents chasing players spaceship in environment with obstacles. Is there a way for a gameobject to follow other gameobjects trajectory using its trail renderer component? I suppose it would involve setpositons or getpositions functions and storing the vertices on to temporary array for the chasing object to follow and destructing them afterwards. I though this would be a better way for the chasing vehicles to get destroyed in collision with obstacles (if the chasers would have different speed and delayed "reaction time" or offset target position) instead of using path finding.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Klarax · Feb 10, 2020 at 02:02 PM

kinda, i expect create ab array or something that records every few seconds its position and rotation.

and then have the object use that to transform to each transform in the array over a given amount of time

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Bitcore · Feb 11, 2020 at 11:17 AM

Thanks for the hint @Klarax , it did help out a lot!

Last night came up with this, works just how intended, at least for now.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class followp : MonoBehaviour
 {
     //public Transform targetP;
     public Vector3 LastTargetPoint;
     //public Vector3 target_Offset;
     public GameObject target;
     public int Current_Position = 0;
     const int MAX_POSITIONS = 10000;
     public Vector3[] TrailRecorded = new Vector3[MAX_POSITIONS];
     public float speed = 20f;

   


 private void Start()
 {
    // target_Offset = transform.position - targetP.position;
 }
 void Update()
 {
     int numberOfPositions = target.GetComponent<TrailRenderer>().GetPositions(TrailRecorded);
    
     speed += 0.25f * Time.deltaTime;

     if (Current_Position < this.TrailRecorded.Length)
     {
        if (LastTargetPoint == null)
             LastTargetPoint = TrailRecorded[Current_Position];

        follow();

     }
 }

 void follow()
 {
         transform.forward = Vector3.RotateTowards(transform.forward, LastTargetPoint - transform.position, speed * Time.deltaTime, 4.0f);

     
     transform.position = Vector3.MoveTowards(transform.position, LastTargetPoint, speed * Time.deltaTime);

         if (transform.position == LastTargetPoint)

         {
           Current_Position++;
           LastTargetPoint = TrailRecorded[Current_Position];
         }
 }
 


 }



Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

119 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make an NPC follow player? 1 Answer

How to make characters follow player like Earthbound? 0 Answers

Want to make GameObject follow another GameObject's path Unity3D 1 Answer

How to make this trail? 1 Answer

Making objects follow each other in a line, and objects ignoring minimum follow distance. 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges