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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question : Rotate player to next waypoint with smoothly (DOTween)

Discussion in 'Scripting' started by NjordNystrom, May 8, 2020.

  1. NjordNystrom

    NjordNystrom

    Joined:
    Feb 29, 2016
    Posts:
    25
    Hello guys, I'm stuck when i want to rotate my player.

    Let me explain my movement. Player start on waypoint1. When player kill enemy at next waypoint player move this waypoint but this waypoint could be at right or left with different angle. I want rotate my player when reach different angle waypoint.
    To this im using this line but my player wont turn any angle? What i missing thanks

    Code (CSharp):
    1. GGun.instance.playerObject.transform.DORotate(new Vector3(newWayPoints[current + 1].wayPoint.transform.rotation.x,
    2. newWayPoints[current + 1].wayPoint.transform.rotation.y,
    3. newWayPoints[current + 1].wayPoint.transform.rotation.z), 10f);
     
    Last edited: May 8, 2020
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,971
    There is no possible way anybody human can reason about that single line of code.

    Break it up into single-statement lines assigning each result to a meaningfully-named intermediate variable, otherwise you will never figure it out except perhaps by chance.
     
  3. NjordNystrom

    NjordNystrom

    Joined:
    Feb 29, 2016
    Posts:
    25
    Well how its look like now ? :D

    I rotate my player with
    Code (CSharp):
    1. GGun.instance.playerObject.transform.rotation = newWayPoints[current + 1].wayPoint.transform.rotation;
    but i want it with smooth animation :D for this i use DOTween but DORotate is not working. Its not rotate. My movement and rotating with no smooth is working perfecly
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,971
    Close this scene, make a fresh scene, make two objects and iterate until you figure out why DOTween is not DORotating. When you figure that out, go apply the knowledge back to your game.
     
    NjordNystrom likes this.
  5. NjordNystrom

    NjordNystrom

    Joined:
    Feb 29, 2016
    Posts:
    25
    Well in empty scene, Its not complete rotating to target object. Now i belive DORotate is not working right :D
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,971
    This is possible, but remember that package has been around a long time. It might be more useful to look for examples of using this package to do exactly what you are doing.
     
  7. NjordNystrom

    NjordNystrom

    Joined:
    Feb 29, 2016
    Posts:
    25
    There is not enough tuts or resources for using of DORotate but i found when digged. They are do same with me but i cant work it properly.


    I set target rotation.y = - 90
    I set my player rotation.y = target.y

    when i run, player only turn at y -0.707 :D

    There is no child no local pos. Cant understand this problem.