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 /
This question was closed Jul 07, 2014 at 01:00 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by user-1246 (google) · Feb 15, 2010 at 07:07 PM · gameobjecttriggerfollow

Problem with trigger

I am new to using unity and I have run into what seems like is a simple problem that I cannot figure out. I want to use a cube as a trigger to make objects follow the first person controller. It seems like it should be pretty straight forward, I have yet to see much documentation about this though. Anyone that can help?

Comment
Add comment · Show 1
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 duck ♦♦ · Feb 15, 2010 at 07:38 PM 0
Share

What do you mean by 'follow'? should they be attached to the first person controller (like collecting a weapon), or chase after (like a creature). What have you tried so far, and where is it failing?

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by Phoskryfes · Oct 30, 2012 at 01:36 AM

I think if you touch the cube, the cube will chase you. That's what I think your question is. Put this to the cube but it will chase you even without triggering. Make the cube into an enemy tag and your player into player tag first before inserting this.

 using UnityEngine;
 using System.Collections;
 
 public class EnemyAI : MonoBehaviour {
     public Transform target;
     public int moveSpeed;
     public int rotationSpeed;
     public int maxDistance;
     
     private Transform myTransform;
     
     void Awake() {
         myTransform = transform;
         target = null;
     }
     
     // Use this for initialization
  IEnumerator Start () {
        yield return new WaitForSeconds(10);
        GameObject go = GameObject.FindGameObjectWithTag("Player");
 
        target = go.transform;
 
        maxDistance = 1;
     }
     
     // Update is called once per frame
     void Update () {
         if(target == null) {
             return;
         }
         Debug.DrawLine(target.position, myTransform.position, Color.yellow);
         
         //Look at target
         myTransform.rotation = Quaternion.Slerp (myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime);
         
         if(Vector3.Distance(target.position, myTransform.position) > maxDistance) {
         //Move towards target
         myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
         }
     }
 }
Comment
Add comment · Show 1 · 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 Phoskryfes · Oct 30, 2012 at 01:49 AM 0
Share

Could you accept my answer by pressing the check button at the left side of my answer?

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

GameObjects creation within boundry 3 Answers

Problem with timed code-execution (audioplay and object destruction) 1 Answer

wall doesnt move after build 0 Answers

How to make a GameObject follow my Player 2 Answers

Camera rotation around player while following. 6 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