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 cgraf1 · Dec 04, 2018 at 04:46 AM · ontriggerenterkinematictransform.translate

Bumping kinematic objects

I have what seems like a small issue, but I really am having trouble getting it to work and I am not sure why.

I have a few objects on a platform that are all supposed to be bumping into each other. Each one of these objects is a parent with a kinematic rigid body which has 3 children, all with colliders and kinematic rigidbodies of their own. I have a script on one of the children, the main "Body" of these objects, that has a script to be pushed back in the opposite direction of the object that they hit. This is happening with OnTriggerEnter.

For some reason sometimes the object go right through each other, instead of the opposite direction, sometimes they go in some random direction. It works great when only one is moving and bumping into a stationary one, but if they are both going full speed, then that is when things go awry. It is even worse when there are more than 2 on the platform.

Here is the script below:

    public class BodyCollision : MonoBehaviour {
 
     private bool hit = false;
     private bool moving = false;
 
     public float distance;
 
     float time = 1.0f;
     Vector3 dir;
 
     GameObject parent;
 
     void OnTriggerEnter(Collider col)
     {
         if(col.gameObject.tag == "Island")
         {
             Debug.Log("Hello");
         }
         else if(col.gameObject.tag != "Island")
         {
             if(hit == false)
             {
                 hit = true;
 
                 if(col.gameObject.tag == "Body")
                 {
                     Debug.Log("happened");
                     dir = transform.root.position - col.transform.root.position;
                     dir.y = 0f;
                     parent = col.transform.root.gameObject;
                     if(parent.tag == "Kart")
                     {
                         dir = -dir;
                         parent.GetComponent<BotController>().bumping = true;
                     }
                     else if(parent.tag == "Player")
                     {
                         parent.GetComponent<PlayerController>().bumping = true;
                     }
                     moving = true;
                 }
                 hit = false;
             }
         }
     }
 
     void Update()
     {
         if(moving == true)
         {
             transform.root.Translate(dir * (Time.deltaTime * (distance/time)));
             StartCoroutine(BumpDelay());
         }
         
     }
     IEnumerator BumpDelay()
     {
         yield return new WaitForSeconds(0.1f);
         moving = false;    
     }
 }

bumping stops the Player and other Bots from moving during the bumps, which is why that is set to 'true' on the bump, but after they are called back to false in their respective control scripts. If it makes a difference, the player is moved with transform.Translate and the Bots are moved with MoveTowards().

I am also using kinematic objects because I want real control of the bumps. I had non-kinematic rigidbodies before with AddForce() on bumps and they would get all tangled up.

I would appreciate any help I can get. Thank you so much.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by cgraf1 · Dec 04, 2018 at 08:54 PM

I realized that I did not normalize the direction of the movement. I have done so since, but it has not led to any better results.

I have also tried changing the OnTriggerEnter to OnCollisionEnter and going to the Physics Manager to enable kinematic-kinematic collisions, but the results were the same.

I would be very grateful if anyone had any other ideas.

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

96 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

Related Questions

How to make kinematic platform trigger events 0 Answers

Setting thrown object to kinematic after hitting target? 1 Answer

Problem with a RigidBody and IsKinematic... I think 1 Answer

Help convert kinematic style movement to Forces. 1 Answer

Check trigger/collider once? 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