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 maxiicanowow · Dec 21, 2018 at 02:46 PM · collisioncolliderscenenpcwalking

when i collide with npc he keeps walking.

so i have a waypoint script on npc's. i also have some kind of dialogue what pops when i hit "e". when i do this on a moving npc he keeps walking. i tried certain things but can't get him to stop....

the collider itself is working, because i do get my camerascript to stop on collision and the text "press E to interract" appears.

any advice would be awesome!!

here is my waypoint script :

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class WaypointSystem : MonoBehaviour {

 public GameObject[] Waypoints;
 public int num = 0;

 public float minDist;
 public float speed;


 public bool rand = false;
 public bool go = true;

 public Animator anim;


 // Start is called before the first frame update
 void Start()
 {
     anim = GetComponent<Animator>();
 }

 // Update is called once per frame
 void Update()
 {

     float dist = Vector3.Distance(gameObject.transform.position, Waypoints[num].transform.position);
   
     if (go)
     {
         if (dist > minDist)
         {
             Move();
         }
         else
         {
             if (!rand) {
                 if (num + 1 == Waypoints.Length)
                 {
                     num = 0;
                 }
                 else
                 {
                     num++;
                 }
             } else
             {
                 num = Random.Range(0, Waypoints.Length);
             }
          
         }
     }
 }


 public void Move()
 {
     anim.SetFloat("speed", speed);
     gameObject.transform.LookAt(Waypoints[num].transform.position);
     gameObject.transform.position += gameObject.transform.forward * speed * Time.deltaTime;
 }

}

i already have a script where i disable certain things, but not the movenement :

using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI;

public class DialogueAppear : MonoBehaviour {

 //[SerializeField] private Canvas customCanvas;
 public GameObject cam;
 public Text text;
 public GameObject walk;
 

 void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("NPC"))
     {
      //   customCanvas.enabled = true;
         cam.GetComponent<CameraControl>().enabled = false;
         text.enabled = true;
         walk.GetComponent<WaypointSystem>().enabled = false;

     }
 }

 void OnTriggerExit(Collider other)
 {
     if (other.CompareTag("NPC"))
     {
       //  customCanvas.enabled = false;
         cam.GetComponent<CameraControl>().enabled = true;
         text.enabled = false;
         walk.GetComponent<WaypointSystem>().enabled = true;

     }
 }

}

New programmer here! any advice would be much appreciated :D sorry for the long read

Comment
Add comment · Show 2
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 Vega4Life · Dec 21, 2018 at 05:10 PM 0
Share

Questions: WaypointSystem is on the NPC? What gameObject is walk? Is DialogeAppear on the NPC? It's important to know what these scripts are on.

avatar image mansoor090 · Dec 21, 2018 at 05:54 PM 0
Share

first . let us know where is collider component ? is it on just NPC or ur character ?

it should be on both, make one of them is trigger and to approach in a fashion way to detect with gameobject collided is to use tag system which u r already doing. now go for the print statements

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jimmycrazyskills · Dec 21, 2018 at 06:28 PM

Hi mate, you could potentially modify your WaypointSystem script to have a canMove variable, then check that canMove is true in your Update function before you actually call the Move function.
You could make this variable public so it's accessible from other scripts (such as your dialog appear script so when a dialog is open canMove is set to false)
This variable could also be set from your collision enter and exit functions to stop the NPC if you walk into it.
Hope this helped =D

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

181 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 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

Terrain collider only detects slow collisions. [VIDEO] 0 Answers

How do I make a scene change when my Player collides with a item? 1 Answer

Help! I am working on a small project that I am having issues with on restarting the level on collision with another object in the scene. 0 Answers

Detect and react to collisions 2 Answers

Character controller sent flying after collision with a moving GameObject 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