Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 KittyKatKat · Apr 03, 2014 at 07:30 PM · c#ontriggerentertag

OnTriggerEnter not working as intended

using UnityEngine; using System.Collections;

public class Lvl9EnemyTeaser : MonoBehaviour {

 public Transform[] point;
 public float speed;

 private int currentPos;

 // Use this for initialization
 void Start () {
     gameObject.transform.position = point[0].position;
     currentPos = 0;
 }
 
 // Update is called once per frame
 void Update () {
     if (transform.position == point [currentPos].position)
         currentPos++;
     if (currentPos >= point.Length)
         currentPos = 0;
     transform.position = Vector3.MoveTowards (transform.position, point [currentPos].position, Time.deltaTime * speed);
 }

 void OnTriggerEnter (Collider tele){
     if (tele.transform.tag == "Teleport") {
         print ("triggered!");
         transform.position = new Vector3(7.5f, 0, 3.5f);
         currentPos++;
     }
 }

}

Now, this is not a player, this just an object going from point A to point B, but when it hits point B, what should happen is that the object looses its render mesh and another one (reciever) turns it self on and does the same at another location (I really hope that it's at least somewhat understandable).

But, object A doesn't detect the trigger at all. I applied rigidbody to the object (A), and put tag on the object that is supposed to be the trigger (and of course put it as a trigger).

Anyone got any ideas?

P.S. If any part of this is not understandable, feel free to say so, I'll try to make it more simple.

Thank you!

EDIT: Edited the main code (reason posted below)

Comment
Add comment · Show 3
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 KittyKatKat · Apr 03, 2014 at 07:02 PM 0
Share

UPDATE: I rethought what I did there and took out the 2 object - illusion of teleportation idea out, and actually tried to teleport the object, but the problem remains where the object doesn't recognize TriggerEnter event.

the OnTriggerEnter event has changed to:

 void OnTriggerEnter (Collider tele){
         if (tele.transform.tag == "Enemy") {
             print ("triggered!");
             transform.position = new Vector3(7.5f, 0, 3.5f);
             currentPos++;
         }
     }

Another P.S. The OnCollisionStay thing from the original post is just something I thought of testing out, but of course, it didn't work.

avatar image udk_lethal_d0se · Apr 03, 2014 at 07:32 PM 0
Share

Does the object that is supposed to trigger the event have a Rigidbody?

avatar image KittyKatKat · Apr 03, 2014 at 08:16 PM 0
Share

Yes, but I haven't configured the rigidbody component on the object. Is that necessary for this to work (I did turn on kinetics, since I didn't want the object to gain gravitational preferences, though)?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by KittyKatKat · Apr 03, 2014 at 11:07 PM

 using UnityEngine;
 using System.Collections;
 
 public class Lvl9EnemyTeaser : MonoBehaviour {
 
     public Transform[] point;
     public float speed;
     public AudioClip audioClip;
 
     private int currentPos;
     
     void Start () {
         gameObject.transform.position = point[0].position;
         currentPos = 0;
     }
 
     void Update () {
         if (transform.position == point [currentPos].position)
             currentPos++;
         if (currentPos >= point.Length)
             currentPos = 0;
         transform.position = Vector3.MoveTowards (transform.position, point [currentPos].position, Time.deltaTime * speed);
         if (currentPos == 2 || currentPos == 5) {
             transform.position = point[currentPos].position;
             TeleportSound ();
         }
     }
 
     void TeleportSound(){
         audio.clip = audioClip;
         audio.Play ();
     }
 }

Well, I'm really not sure why Unity doesn't like my object being detected (Yea, I did use the rigidbody and all needed (I think/hope!), BUT I did find an alternative. It doesn't actually do an OnTriggerEvent, but it solves the issue.

Basicly it tests the 2 positions from which it would normally enter the trigger and just teleports the object to the next location with the sound that I implemented. It still doesn't 'work as intended', but it's a quick fix.

Posted for someone who might have a similar problem and could use this idea.

However, if anyone has any idea what caused the original problem, answers are always welcome. ^^

Cheers.

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

20 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

Related Questions

Multiple Cars not working 1 Answer

GameObject tag to if condition 1 Answer

Distribute terrain in zones 3 Answers

AI Attack Not Working! W/Video 1 Answer

Checking Tag of Trigger Prefab 1 Answer


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