Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Hel with object rotation

Discussion in 'Scripting' started by Sylon87, Dec 20, 2018.

  1. Sylon87

    Sylon87

    Joined:
    Aug 20, 2018
    Posts:
    196
    hi everyone.
    Let me explain what issue i have.

    I want to rotate an object and let it flip from an position to another, like a pendulum, and what i have is this

    Code (CSharp):
    1. Vector3 movePos = new Vector3(0.0f,1.0f,0.0f);
    2.  
    3.         float angle = Mathf.Sin(Time.time * Mathf.PI * 0.5f) * targetangle;
    4.        
    5.         _playerArray[id].transform.rotation = Quaternion.Euler(angle,0.0f,90.0f);
    That is working well, but nio at all when i want to increase that target angle object do a little strange twitch.

    How to make it smoth?

    Anyone can help me?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,598
    It will increase smoothly if you increase the targetAngle smoothly. Instead of changing it from 10 to 20, use a coroutine to slowly move it there in smaller steps.
     
    Sylon87 likes this.
  3. Sylon87

    Sylon87

    Joined:
    Aug 20, 2018
    Posts:
    196
    Thank’s u, sometimes i’m so stupid.. :)
     
    Kurt-Dekker likes this.