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 /
  • Help Room /
avatar image
0
Question by Nova-1504 · Nov 30, 2016 at 06:21 PM · navmeshfunctionnavmeshagentfollowfollow player

Is there a way to make a follow script without NavMesh?

Is there a way to make a character move towards the player, exactly like Nav but not since Nav breaks my game? Can you post the script please?

I need an answer TODAY!

Comment
Add comment · Show 7
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 TreyH · Dec 01, 2016 at 04:19 PM 0
Share

Clearly there are games that do not use Unity's navmesh and still have AI pathfinding and whatnot, so it becomes a question of how much work you are willing to do to that end.

It's important to ask the right questions. The answer to your current question posed here is "yes, of course", but it sounds like the actual question you want to ask is "what happened to my project to break the navmesh system?"

avatar image Nova-1504 · Dec 01, 2016 at 05:33 PM 0
Share

Do you know what happened? Look at the link.

avatar image TreyH · Dec 01, 2016 at 06:21 PM 1
Share

It sounds like this is something for work or school (by the deadline), so the urgency is noted.

What are you looking for as far as "follow script" is concerned? Just something to slowly approach some other object? You presumably care about obstacles, or you likely wouldn't bother with setting up a navmesh agent system.

avatar image Nova-1504 TreyH · Dec 01, 2016 at 10:25 PM 0
Share

I need a script that will work with the currently existing Third Person Character (Ethan) standard asset animation. Just a basic "approach" script. Having an obstacle avoidance would be helpful but not necessary. You guessed correctly about the school project, I won't get more than an hour to work on it after tomorrow.

avatar image TreyH · Dec 02, 2016 at 01:50 PM 1
Share

There is a bit here, but this will be 90% comments as this seems to be for class / education.

Create an empty scene, make two cubes, attach this to one of them. Then set the other cube as its follow target.

It will look like this: **http://i.imgur.com/FwX4wxU.gifv**

 using UnityEngine;
 using System.Collections;
 
 public class SimpleFollow : $$anonymous$$onoBehaviour
 {
     // Pick a target to see how this works
     public float followSpeed = 0.1f;
     public Transform followTarget;
 
     // Update is called once per frame
     void Update ()
     {
         // Call the function we wrote below.  It can get a bit ugly
         // if you put a bunch of code in a function like Update().
         //
         this.Follow (this.followTarget, fSpeed: this.followSpeed);
     }
 
     void Follow (Transform target, float fSpeed = 1)
     {
         // There are more elegant and modular ways to do this, but it sounded like
         // you needed a very simple example to get started.
         //
         // First, we'll deter$$anonymous$$e how much we should 
         // be moving.  Vector3.$$anonymous$$oveTowards() will give 
         // you a vector in the direction we want and 
         // then set that vector's magnitude to whatever 
         // we supply for the 3rd parameter.  In this case, 
         // we're calling this every frame, so we want 
         // to move a certain amount of units each second.  
         // We accomplish this by multiplying that distance 
         // by the change in time.
         //
         Vector3 newPosition = Vector3.$$anonymous$$oveTowards(this.transform.position, target.position, fSpeed * Time.deltaTime);
 
         // If you wanted to update the animations, you might do so here.  
         // Animation control schemes vary from project to project, 
         // so your own code will differ from someone else's.
         //
         /* Animation stuff here */
     
         // Lastly, assign the values we calculated above
         this.transform.position = newPosition;
         this.transform.LookAt (target.position, this.transform.up);
     }
 }
 
avatar image Nova-1504 TreyH · Dec 02, 2016 at 02:43 PM 0
Share

I'm using the existing Ethan prefab animator, can you edit the script to take that into account? I tried myself, but I can't get it to work.

avatar image TreyH · Dec 02, 2016 at 05:25 PM 0
Share

I'm not familiar with that specific controller, but this is your assignment. I was hesitant to even post that much, but the desperation egged me beyond typical scaffolding territory.

These forums are not a place where you should look for homework problems to be magically solved. You have nearly all of the work done for you, with the remaining problem being syncing an animation to this.

Hint: magnitude comes into play.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Jimmy_Jonno · Jun 19, 2017 at 10:44 AM

@Nova-1504

Hey there. First of all sorry for my bad english. If you are still asking how to do that,here is a code that I made some weeks ago. Unfortunatley this code let the character move through walls and collider obstacle.

 float moveSpeed=3.0f;
 private GameObject character;
 public GameObject player;
 void Start(){
 character = GetComponent<GameObject>();
 player=GameObject.Find("Player");
 } 
 
 void Update(){
 //code for looking to player
 character.transform.rotation = Quaternion.Slerp(character.transform.rotation,
 Quaternion.LookRotation(player.transform.position - character.transform.position), 3 * Time.deltaTime);
 
 //code for following the player
 character.transform.position += character.transform.forward * moveSpeed * Time.deltaTime;
 }
 
 
         


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

80 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

Related Questions

Navmesh agent enemy moving to players last seen position 0 Answers

How do I make enemies that avoid player? 0 Answers

Navmesh dont work! 0 Answers

Having some problem with AI finding a vector3... 0 Answers

Is there anyway to avoid a StackOverflow 0 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