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

How to rotate your character's focus in 8-way combat???

Discussion in 'Scripting' started by voltage, May 27, 2015.

  1. voltage

    voltage

    Joined:
    Nov 11, 2011
    Posts:
    515
    So I'm working on an 8-way combat game. For those of you who don't know the term, it's like Tekken, DOA, Soul Calibur, etc. I know how to make players fight and all that jazz, but how do I make sure that no matter where my character is going, he's focusing on the other player with his sight? Obviously I tried rotating the character model when walking up or down, but that makes him rotate in circles and the illusion of focus is broken once that occurs. It's been awhile since I've coded, so please forgive my rustiness. I've tried googling this problem, but all I get are hits for camera focus and not player model focus.
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Transform.LookAt?
     
  3. voltage

    voltage

    Joined:
    Nov 11, 2011
    Posts:
    515
    I did come across that too, but I don't really understand the demonstration in the scripting reference. I should've added that to my original post. Can you dumb it down for me?
     
  4. hamsterbytedev

    hamsterbytedev

    Joined:
    Dec 9, 2014
    Posts:
    353
    Code (CSharp):
    1. this.transform.LookAt(target);
     
  5. voltage

    voltage

    Joined:
    Nov 11, 2011
    Posts:
    515
    After realizing target was a transform and not a gameobject, I was able to dump a gameobject into the inspector and it worked great. Haha. Thanks a lot guys.
     
  6. hamsterbytedev

    hamsterbytedev

    Joined:
    Dec 9, 2014
    Posts:
    353
    No problem. Glad to be of service. Best of luck in all your future endeavours!