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 serenefox · Mar 17, 2013 at 10:40 AM · collisionrigidbodyontriggerenterwaypoints

Waypoint Question(Conflicting Collision)

I found a waypoint script on this awnsers site that Im sure everyone is familiar with(and altered it a bit):

 var waypoints : GameObject[];
 var speed : float = 3;
 public var currentWaypoint : int;
 
 
 function Start()
 {
     waypoints = GameObject.FindGameObjectsWithTag("BossWaypoints");
 }
 
 function Update () 
 {
     if(currentWaypoint < waypoints.length)
     {
          var target : Vector3 = waypoints[currentWaypoint].transform.position;
          var moveDirection : Vector3 = target - transform.position;
          var velocity = rigidbody.velocity;
          
         if(Vector3.Distance(transform.position, waypoints[currentWaypoint].transform.position) < 50 )
         {
              currentWaypoint++;
         }
         else
         {
             velocity = moveDirection.normalized*speed;
         }
         rigidbody.velocity = velocity;
     }
     else
     {
         currentWaypoint = 0;
     }
     
 }

But my question lies with the rigidbody that is required for this script to work. When I have a rigidbody attached to the parent object(which also holds this script), the child objects' collision under it doesn't recieve damage or allow the OntriggerEnter to activate. How do I get the function for the child to work if the rigidbody is stopping it? This is the script that is on the child along with the collision:

 var hp : float;
 var replacementSpawn : GameObject[];
 var replacement : GameObject[];
 var scoreAmount : int = 0;
 var scoreHolder : GameObject;
 var turretReplacement : Transform;
 var turretMaterial : Material;
 var regularTexture : Texture2D;
 var changedTexture : Texture2D;
 
 function Start()
 {
     turretMaterial.mainTexture = regularTexture;
 }
 
 function OnCollisionEnter(collision : Collision)
 {
     turretMaterial.mainTexture = changedTexture;
     yield WaitForSeconds(0.1);
     turretMaterial.mainTexture = regularTexture;
 }
 
 //Take Damage Function
 //Subtract damage from hp
 
 function TakeDamage( damage : float )
 {
     hp = hp - damage;
     if(hp <= 0)
     {
 
         var i : float = 0;
         
         while( i < replacementSpawn.Length)
         {
             var y : float = 0;
             while( y < replacement.Length)
             {
                 replacementSpawn[i] = Instantiate(replacement[y], transform.position, transform.rotation);
                 replacementSpawn[i].transform.parent = turretReplacement;
                 y++;
             
             }
             i++;
         }
         scoreHolder = gameObject.Find("ScoreText");
         scoreHolder.SendMessage("ScorePoints", scoreAmount );
         SendMessage("Die", SendMessageOptions.DontRequireReceiver);
         Destroy(gameObject);
     }
 
 }
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 serenefox · Mar 17, 2013 at 09:17 PM 0
Share

Can anyone help me with this? What I am trying to do is move my enemy Boss back and fourth between two points and it works, but because I have a rigidbody attached to allow the script to work, the turrets' collision on the boss that are children to the mesh don't receive damage or the OnCollisionEnter that I have doesn't register either. Its because of the rigidbody, I tested each component and thats what does it.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by nsxdavid · Mar 18, 2013 at 05:32 AM

All child object's that have colliders report their collision events to the class wit hthe rigidbody. This is expected behavior. In this way you can create a complex collision shape from many child colliders.

One answer would be to move the functionality to the parent object's script. But it all depends on what you are after.

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 serenefox · Mar 18, 2013 at 07:01 AM 0
Share

Im not sure moving the functionality to the parent will work because each collision is a turret with a separate turret mesh. So they can be destroyed separately.

I tried giving each turret a rigidbody and they worked but then they acted like they weren't a child to the parent object anymore because they stayed inplace while the parent followed the waypoints.

Also what i am try to achieve is in my question asa comment, "What I am trying to do is move my enemy Boss back and fourth between two points and it works, but because I have a rigidbody attached to allow the script to work, the turrets' collision on the boss that are children to the mesh don't receive damage or the OnCollisionEnter that I have doesn't register either. Its because of the rigidbody, I tested each component and thats what does it."

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

11 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

Related Questions

Player colliding with pickable object 0 Answers

Transform collider not detecting collision on rigidbody collider 2 Answers

100 OnTriggerEnter Or Tags each player too much? 3 Answers

Child calling parent's OnTriggerEnter when no Rigidbody is attached to child 1 Answer

OnTriggerEnter not working, tried everything! :( (C#) 3 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