Search Unity

  1. Unity 2019.4 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  3. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Clamp Y with Rigidbody character using addforce (drone)

Discussion in 'Scripting' started by donovand4, Jul 11, 2019.

  1. donovand4

    donovand4

    Joined:
    May 8, 2013
    Posts:
    3
    Hi All,
    Im struggling with clamping my character to the camera bounds. For some reason when the character reaches the clamp it begins to jitter. I have tried different force methods, clamp positions vs velocity but I really do need some help as I am not a very experienced coder.

    The project is a side scroller using 3d meshes and the character needs to feel like a drone which is why I am using addforce instead of position.

    transform.position = new Vector3(transform.position.x, Mathf.Clamp(transform.position.y, -2f, 5.1f), transform.position.z);

    //input region for managing the movement of the character
    //Upwards movement
    if (Input.GetAxis("Vertical") > 0.0f)
    {
    //rigidbodyCharacter.AddForce(0, Upwardthrust, 0, ForceMode.Acceleration);
    rigidbodyCharacter.AddForce(0, Upwardthrust, 0, ForceMode.Force);
    }

    Any ideas?
     
    Last edited: Jul 12, 2019
  2. LilFire

    LilFire

    Joined:
    Jul 11, 2017
    Posts:
    58
    Do you use Update() or FixedUpdate()?
     
  3. donovand4

    donovand4

    Joined:
    May 8, 2013
    Posts:
    3
    FixedUpdate()
     
  4. donovand4

    donovand4

    Joined:
    May 8, 2013
    Posts:
    3
    Fixed it by removing the forcemode and reducing the parameters to the minimum required.

    rigidbodyCharacter.AddForce(Vector3.up * Upwardthrust);
     
unityunity