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 RosieSpudMole · Sep 01, 2014 at 03:36 PM · c#movementrigidbodypositionjittering

C#: Why does this strange jittering occur??

Hello! I have a scene in which the player can pick up and drop objects, as well as move and look around.

All player objects are children of an empty game object "MainCharacter":

MainCharacter > Capsule (With RigidBody and PlayerMoveScript)> PlayerBase (empty - used for checking if grounded) MainCamera> Hands(With PickUpDrop script)

The object I pick up Lerps to my Hands position, however after my capsule collides with any walls there is a strange jittering which I cannot work out how to fix!!

Heres the .exe:GameTest Heres the data folder : Data

If anyone can figure out how to stop this i would be very very grateful!

Thank you :)

Here are the scripts:

Pick Up and Drop Script:

 public bool handsFull = false;
     
     public float distanceMax = 20f;
 
     public Transform handPosition;
 
     public LayerMask canPickUp;
     
     public GameObject taggedGameObject;
 
     public bool colliderTriggered;
 
     public bool bounds;
 
     public PickedUpObject pickedUpScript;
 
     public Rigidbody player;
 
     // Use this for initialization
     void Start () {
 
         print(FindClosestPickup().name);
         handPosition = transform;
         pickedUpScript = null;
     
     }
     
     // Update is called once per frame
     void Update () {
 
 
                 if (Input.GetKeyDown (KeyCode.E) && !bounds) {
                         if (Physics.CheckSphere (handPosition.position, 2f, canPickUp)) {
 
                                 if (handsFull) {
                                         Drop ();
                                 }
 
                                 if (!handsFull) {
                                         PickedUp ();
                                 }
 
                 handsFull = !handsFull;
 
                         }
                 }
 
                 if (handsFull) {
                         RotateMovePickedUpObject();
                 }    
 
 
         }
 
 
 
     private void PickedUp(){
 
         //Closest object to top of list
         taggedGameObject = (GameObject)FindClosestPickup();
 
         taggedGameObject.collider.isTrigger = true;
 
 
 
         taggedGameObject.rigidbody.useGravity = false;
         taggedGameObject.rigidbody.isKinematic = true;
 
         pickedUpScript = taggedGameObject.GetComponent<PickedUpObject> ();
 
         Debug.Log ("Pick Up");
 
     
     }
 
     private void RotateMovePickedUpObject(){
 
         //Rotate
 
         if(Input.GetKeyDown(KeyCode.End)){
             taggedGameObject.transform.localRotation *= Quaternion.Euler(0, 0, 45);
         }
         if(Input.GetKeyDown(KeyCode.Delete)){
             taggedGameObject.transform.localRotation *= Quaternion.Euler(0, 45, 0);
         }
         if(Input.GetKeyDown(KeyCode.PageDown)){
             taggedGameObject.transform.localRotation *= Quaternion.Euler(0, -45, 0);
         }
         if(Input.GetKeyDown(KeyCode.Home)){
             taggedGameObject.transform.localRotation *= Quaternion.Euler(0, 0, -45);
         }
         if(Input.GetKeyDown(KeyCode.PageUp)){
             taggedGameObject.transform.localRotation *= Quaternion.Euler(-45, 0, 0);
         }
         if(Input.GetKeyDown(KeyCode.Insert)){
             taggedGameObject.transform.localRotation *= Quaternion.Euler(45, 0, 0);
         }
 
         taggedGameObject.transform.position = Vector3.Lerp(taggedGameObject.transform.position, handPosition.position, (1 - Mathf.Exp( -20 * Time.smoothDeltaTime )) * 10);
 
     }
 
     
     private void Drop(){
 
         taggedGameObject.collider.isTrigger = false;
 
         taggedGameObject.rigidbody.useGravity = true;
         taggedGameObject.rigidbody.isKinematic = false;
 
         taggedGameObject = null;
 
         Debug.Log ("Drop");
 
         pickedUpScript = null;
 
     }
 
     private GameObject FindClosestPickup() {
 
         //Find closest gameobject with tag
         GameObject[] gos;
         gos = GameObject.FindGameObjectsWithTag("pickup");
         GameObject closest = null;
         float distance = Mathf.Infinity;
         Vector3 position = transform.position;
 
         foreach (GameObject go in gos) {
             Vector3 diff = go.transform.position - position;
             float curDistance = diff.sqrMagnitude;
             if (curDistance < distance) {
                 closest = go;
                 distance = curDistance;
             }
         }
 
         return closest;
     }
 
 }

The Picked Up Objects Script:

 public PickUpDrop pickUpScript;
     public GameObject thisOne;
     public Color thecolor;
     public bool inObject;
 
     // Use this for initialization
     void Start () {
         thisOne = this.gameObject;
     }
     
     // Update is called once per frame
     void Update () 
     {
         thecolor = thisOne.renderer.material.color;
 
     if (pickUpScript.taggedGameObject != thisOne)
         {
             gameObject.renderer.material.color = Color.gray;
         }
 
     if (pickUpScript.taggedGameObject == thisOne)
         {
             Color color = renderer.material.color;
             color.a = 0.5f;
             renderer.material.color = color;
         }
     }
 
     void OnTriggerEnter ()
     {
         if (thisOne == pickUpScript.taggedGameObject)
         {
             inObject = true;
             pickUpScript.bounds = true;
             gameObject.renderer.material.color = Color.red;
 
         }
     }
 
     void OnTriggerExit()
     {
         if(thisOne == pickUpScript.taggedGameObject)
         {
             inObject = false;
             pickUpScript.bounds = false;
             gameObject.renderer.material.color = Color.gray;        
         }
     }
 
 }


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

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.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Making a bubble level (not a game but work tool) 1 Answer

Why does my character keep sliding around? Help! (Rigid Body) 1 Answer

Moving a Rigidbody Relative to Camera Direction 0 Answers

Move left etc. according to where player faces 1 Answer

Guided missile help c# 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