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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Move sprite to mouse click position with forward facing rotation

Discussion in 'Scripting' started by VOiD-Games, Oct 28, 2015.

  1. VOiD-Games

    VOiD-Games

    Joined:
    Dec 7, 2012
    Posts:
    8
    Hi everyone,

    The game i'm developing is top down 2D and I want the user to be able to explore the world.

    I have some code that gets a the users mouse click position (raycast) and moves my sprite to that location. My problem is that I can't get the sprite to face the direction its traveling. If I move the sprite it faces the same direction as its default (i would describe it as north).

    I have been through a few options with moving its z axis rotation value but none of them are smooth, or none of them work consistently. I have also tried to use Quaternion.Lerp but with erratic results.

    Could anyone help me out on this one. I'm truly stumped.

    Thanks, Chris.
     
  2. vintar

    vintar

    Joined:
    Sep 18, 2014
    Posts:
    90