Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Dorscherl · Jul 13, 2017 at 06:21 PM · script.cursorheadheadlookcontroller

How do I make my model's head and body rotate with the mouse?

How do I make my model's head and body rotate with the mouse?

More specifically, I want the player's head to rotate accordingly to the player mouse. I want the model to looks up when the player looks up, look down when the player looks down, and look left and right when the player does the same.

When looking left or right I want the head to rotate 90 degrees both directions before turning the body and when the player starts walking/running the body with rotate accordingly. Very complex I imagine but please help. THANK YOU!

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Cherno · Jul 13, 2017 at 07:07 PM 0
Share

Use the HeadLookController and/or an I$$anonymous$$ solution.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by TonyLi · Jul 13, 2017 at 07:18 PM

If you're using a Mecanim Humanoid character, write a script with an OnAnimatorIK method. In the method, call Animator.SetLookAtPosition() to set the position. (You can also use SetLookAtWeight to specify how much head and body rotation to use.)

To determine the position, use Camera.ScreenToWorldPoint to convert Input.mousePosition to a world space position.

This will handle looking.

Turning the character's feet to face the mouse cursor is a little more complicated. You'll want to do a little math to determine the angle between the character's forward direction and the direction to the mouse cursor using Vector3.Angle(). If it exceeds a must-turn threshold, start playing a turn-in-place animation until it's below a can-stop threshold.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dorscherl · Jan 28, 2018 at 04:27 PM 0
Share

Would using Input.mouseposition work with Joystick input? If not is there an alternative? Currently I have a gameobject in the scene that is set as the lookat target and I control that with mouse, only problem is I get this weird effect when I control it at the clamped angle

avatar image Rugbug_Redfern · Mar 31, 2019 at 01:55 PM 0
Share

This is a bit late but if your mouse is always in the center of your screen then you can just use new Vector2(0.5f, 0.5f) to replace Input.mousePosition.

avatar image
0

Answer by Artieman · Aug 25, 2020 at 12:49 AM

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class MouseAim : MonoBehaviour {

 public float speedH = 2.0f;
 public float speedV = 2.0f;

 private float yaw = 0.0f;
 private float pitch = 0.0f;



 // Use this for initialization
 void Start()
 {

 }

 // Update is called once per frame
 void Update()
 {

     yaw += speedH * Input.GetAxis("Mouse X");
     pitch -= speedV * Input.GetAxis("Mouse Y");

     transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);

 }

}

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Artieman · Aug 24, 2020 at 11:22 PM 0
Share

this is the code i got from a video https://www.youtube.com/watch?v=lYIRm4QEqro to download the code https://www.youtube.com/redirect?q=https%3A%2F%2Fdrive.google.com%2Fopen%3Fid%3D0B__1zp7jwQOKX1Y0amo0dWIxTW8&event=video_description&redir_token=QUFFLUhqbXloUlpzR1Z0eTVXcVlsSy1y$$anonymous$$WZvcFljdS00UXxBQ3Jtc0trOEYzYjgtU1JwZWh4bGFv$$anonymous$$DVX$$anonymous$$nNj$$anonymous$$WV2dGFJUHdHRlNuczJQcWEzZkx4eHZnNFNoT0t6d1Q1TGV0ZndoZ0Fq$$anonymous$$URyV3dURVFHcmNNV3FqRnJfOEg2QWZlRmFEOV9TeDgwazRPSmU5d1hudkp0NHVRVQ%3D%3D&v=lYIRm4QEqro

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

75 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to change the color of a UI cross hair using Raycasts 1 Answer

Is There A Horizontal AND Vertical Head Bobbing Script? 0 Answers

Admob Rewarded Video are not showing 0 Answers

loading information from a file 0 Answers

loop vs if spell casting script 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges