Forum rules - please read before posting.

Q: Turning following the mouse??

edited May 2014 in Technical Q&A
Is there a way to set up your player character to turn following the mouse pointer while its standing still...

I was planning on using Partel's FINALIK to use the LookatIK to have my character's head and eye's follow the mouse but I was thinking wouldn't it be cool if the character turned 90 degrees after my mouse crossed 90 degrees, that way the character is always facing towards the direction the player wants to go... I thought it would add a cool factor to the player experience...


Comments

  • Something this specific to your game would need a custom script.  You'd have to work out the direction vector yourself, based on your game/input style, but updating the player once you have it is quite straightforward:

    Player player = GameObject.FindWithTag (Tags.player).GetComponent <Player>();
    if (player.charState == CharState.Idle)
    {
      player.SetLookDirection (lookVector, true);
    }


    Also be sure to include the "AC" namespace in your script.
  • Thanks Chris, a lot of times my imagination goes beyond my skills, I will ask the unity forums on how to capture the mouse pointer's direction vector within a scene, at least I know whats it's called HA!

    Thanks again...
  • Chris the code snippet below is from Partel Lang because I plan to use his LookAtIK solution to control the head eyes and upper torso to follow my mouse pointer, he gave me this to have the character turn to follow the mouse pointer.
    1. Vector3 direction = lookAt.solver.IKPosition - character.position;
    2. float angle = Mathf.Atan2(directionLocal.x, directionLocal.z) * Mathf.RadToDeg;
    3.  
    4. if (angle >= 45 && angle < 180) animator.CrossFade("TurnLeft", transitionDuration);
    5. if (angle >= 180 && angle < 315) animator.CrossFade("TurnRight", transitionDuration);
    Question is would I put this in the character controller script in AC?

    Sorry to be such a goof... I'm a modeler/animator/story teller, not a coder, any help would be greatly appreciated.

    Thanks again Chris!
  • I'm not familiar with LookAtIK, so I can't give a proper answer, but I shouldn't think you'd need to edit any AC scripts - so long as you're only manipulating the Player Animator rather than the AC Player itself.

    I'd change the TurnLeft / TurnRight parameter names to something like LookLeft / LookRight, and just update your Mecanim FSM to accomodate it.  I'm not sure where this InverseTransformDirection function comes from, but I'm assuming that's part of the LookAtIK asset.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.