Search Unity

Making transform smoother.

Discussion in 'Scripting' started by DouglasPotesta, Dec 18, 2014.

  1. DouglasPotesta

    DouglasPotesta

    Joined:
    Nov 6, 2014
    Posts:
    109
    Hi. I'm new to these forums. I've been messing around with unity for about a month now, and I'm finally getting the hang of it.
    I made a script for picking up objects and It works great, but the objects move a little choppily.

    The script works by making an empty game object(player). I put in the first person character controller as a child. I put a sphere under the first person character controller camera as a child of the camera. The sphere is kinematic and acts a trigger.

    here is the script.

    Code (CSharp):
    1. usingUnityEngine;
    2. usingSystem.Collections;
    3.  
    4. publicclasspickuprigidbodies : MonoBehaviour {
    5. privateVector3cursor;
    6. privateboolgrabbable;
    7. privateboolgrabbed;
    8. privatebooldropped;
    9. privateboolfree = true;
    10. privateCollidercarried;
    11. publicfloatthrowspeed;
    12.  
    13. voidOnTriggerStay (Colliderother)
    14. {
    15. carried = other;
    16. if (other.GetComponent<Rigidbody> () != true)
    17. {
    18. }
    19. elseif (free == true)
    20. {
    21. grabbable = true;
    22. }
    23. }
    24. voidFixedUpdate()
    25. {
    26.  
    27. if (grabbable != true)
    28. {
    29. }
    30. elseif (carried.GetComponent<Rigidbody> () != true)
    31. {
    32. }
    33. elseif(Input.GetKey (KeyCode.Mouse0))
    34. {
    35. cursor = transform.position;
    36. Vector3speed = newVector3 (0.0f, 0.0f, 0.0f);
    37. carried.rigidbody.position = cursor;
    38. carried.rigidbody.velocity = speed;
    39. carried.rigidbody.freezeRotation = true;
    40. grabbed = true;
    41. }
    42. elseif(Input.GetKeyUp (KeyCode.Mouse0))
    43. {
    44. Vector3speed = transform.position - carried.transform.position;
    45. carried.rigidbody.AddForce (speed * throwspeed);
    46. Debug.Log (carried.rigidbody.angularVelocity);
    47. grabbed = false;
    48. free = true;
    49. }
    50. if (grabbed == true)
    51. {
    52. free = false;
    53. }
    54. }
    55. }
     
    Last edited: Dec 18, 2014