• 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
Question by SovietBear · Dec 27, 2016 at 04:10 PM · c#collisionphysicsrigidbodyrigidbody2d

Issue with adding force and lerping position? Possible unity bug?

The Bouys in my boat game aren't acting correctly when shot. When the rigid body is normally pushed by another rigidbody it will be pushed, and due to t$$anonymous$$s script:

 using UnityEngine;
 using System.Collections;
 
 public class buoyScript : MonoBehaviour {
 
     Vector3 startPos;
     public float bounceBack = 0.5f;
 
     // Use t$$anonymous$$s for initialization
     void Awake () {
         startPos = transform.position;
     }
     
     // Update is called once per frame
     void FixedUpdate () {
             transform.position = Vector3.Lerp (transform.position, startPos, bounceBack);
     }
 }
 

And t$$anonymous$$s script for the shots:

 using UnityEngine;
 using System.Collections;
 
 public class shotScript : MonoBehaviour {
 
     public float shotVel = 10;
     public float $$anonymous$$tVel = 10;
 
     public int shotDam = 0;
 
     public string tarTag = "Enemy";
 
     public Rigidbody2D RB;
 
     // Use t$$anonymous$$s for initialization
     void Start () {
         RB = gameObject.GetComponent<Rigidbody2D> ();
         RB.velocity = shotVel * transform.up;
     }
 
 
     void OnTriggerEnter2D(Collider2D col){
         
         if (col.tag == tarTag) {
             col.gameObject.SendMessageUpwards ("hurt", shotDam);
         }
 
         if(col.gameObject.GetComponent<Rigidbody2D>() != null){
             var colRB = col.gameObject.GetComponent<Rigidbody2D> ();
             colRB.AddForce ($$anonymous$$tVel * transform.up, ForceMode2D.Impulse);
         }
 
         Destroy (gameObject);
     }
 }
 

Here is a video of the behavior as an example.

Notice how the boat can push the bouy and it will bounce back as programmed, but when shot it will cause it to not bounce back until the bout touches it again. The boat never sends any message to the bouy upon touch, all t$$anonymous$$s is done by the bouy script and unity's built in rigidbody system, the only exception to that is the shot. Even weirder is the fact that the particles act correctly to the bouy after being shot, but the boat collides with it at a different area, showing that where the rigidbody believes the collider is, and where the collider actually is are at two different locations.

Comment

People who like this

0 Show 9
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 TheFish657 · Dec 27, 2016 at 04:27 PM 0
Share

Is your bouy object a child of any other object?

avatar image SovietBear TheFish657 · Dec 27, 2016 at 04:30 PM 0
Share

It is, but after testing, it seems that even if it isn't a child of any object it still has the same behaviors.

avatar image TheFish657 SovietBear · Dec 27, 2016 at 04:31 PM 0
Share

Can I see a picture of your heirarchy please, to see if I can recreate this?

Show more comments
avatar image TheFish657 · Dec 27, 2016 at 04:33 PM 0
Share

And all the objects have colliders on them?

avatar image SovietBear TheFish657 · Dec 27, 2016 at 04:36 PM 0
Share

Yeah, although the cannon balls are triggers if that matters.

avatar image SovietBear SovietBear · Dec 27, 2016 at 04:46 PM 0
Share

I find that using the velocity and mass of the built in physics system by changing the cannon balls from triggers to normal colliders simply works better, and makes the bouys behave correctly. Either way I feel this bug has more to do with an issue with Unity than my code. I might be wrong, but i really can't figure out what I did wrong.

avatar image TheFish657 · Dec 27, 2016 at 05:24 PM 0
Share

I can't seem to be able to figure it out. I'm sorry, I tried everything I could but I can't see why this isn't working.

avatar image SovietBear TheFish657 · Dec 28, 2016 at 02:49 AM 0
Share

Don't worry about it. I found away around it, while also making my cannon balls preform better in the process anyways. It's probably an engine bug and not problem with my code. Although I should probably see about getting a bug report submitted about this entire situation. Thanks for all of your help!

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

293 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Handling colliders on hundreds of asteroids (not procedural asteroids) ...URGENT 3 Answers

How to change CC script to Rigidbody script 1 Answer

I need the ability to disable the functionality of a Rigidbody without deactivating it's GameObject, removing it, or changing any of it's physics settings 0 Answers

Making Objects and Piling them up , 0 Answers

Vibrating GameObjects 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