Beginner question about rotation a Rigidbody2D to face the direction of movement

Forums 💬 FlowCanvas ⚙️ Support Beginner question about rotation a Rigidbody2D to face the direction of movement

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #22743
    jn2002dk
    Participant

      Hello

      I’ve just purchased this brilliant asset in an effort to move away from the limitations of Playmaker

      Since i’m an artist and have only superficial knowledge of programming please excuse any stupid questions i might have

      So to start out with Flow Canvas i decided to recreate a simple 2d top down movement i made in PM a while back. Getting the sprite to move was extremely easy but i must be missing something when it comes to rotating it to face the direction of movement

      Normally i’d do

      Vector2 moveDirection = gameObject.rigidbody2D.velocity;
      float angle = Mathf.Atan2(moveDirection.y, moveDirection.x) * Mathf.Rad2Deg;
      transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);

      But i can’t find anything resembling Mathf.Rad2Deg so how do i go about achieving this?

      #22745
      Gavalakis
      Keymaster

        Hello,

        Thanks a lot, I am glad you like FlowCanvas!
        The Rad2Deg is a field and right now fields can not be used with FlowCanvas for performance reason, but I will make it possible in the next version.
        To work around this for now, the easiest way would be to create a float variable in your flowscript named “Rad2Deg” and give it a value of “57.29578” which is exactly what Mathf.Rad2Deg return (it’s a constant value).

        Let me know if that works for you and thanks again.

        #22744
        jn2002dk
        Participant

          I love FlowCanvas

          Your solution works perfectly

          Thanks!

        Viewing 3 posts - 1 through 3 (of 3 total)
        • You must be logged in to reply to this topic.