Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Jasper Hesseling · Oct 30, 2011 at 09:49 AM · headlookcontroller

Head Look Controller with camera

I have integrated the Head Look Controller script in my character and it works like a charme. Now in stead of a GameObject I want it to look at the Main Camera which can be controlled by the user. It all works but at a certain point the camera goes all over the place. I think it has something to do with the code in the "Cursor Hit" c#.

 using UnityEngine;
 using System.Collections;
 
 public class CursorHit : MonoBehaviour {
     
     public HeadLookController headLook;
     private float offset = 1.5f;
     
     // Update is called once per frame
     void LateUpdate () {
         if (Input.GetKey(KeyCode.UpArrow))
             offset += Time.deltaTime;
         if (Input.GetKey(KeyCode.DownArrow))
             offset -= Time.deltaTime;
         
         Ray cursorRay = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit hit;
         if (Physics.Raycast(cursorRay, out hit)) {
             transform.position = hit.point + offset * Vector3.up;
         }
         
         headLook.target = transform.position;
     }
 }

What I want is that the camera stays under control of the user. I've tried to alter the code but I don't know what to delete to just simplify it as the lookat target.

Thanks

Comment
Add comment · Show 8
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 syclamoth · Oct 30, 2011 at 09:51 AM 0
Share

I'm afraid I don't quite understand what you're trying to do here. Is the camera controlled at all by the headlook function? Does the headlook look at the camera, or at a point in the world?

avatar image Jasper Hesseling · Oct 30, 2011 at 12:11 PM 0
Share

It's quite simple. I want just the target to be the camera. So the characer is always trying to look at you as the viewer. So the whole setup for controlling the target needs to be chopped out.

avatar image syclamoth · Oct 30, 2011 at 12:27 PM 0
Share

Right, that makes sense. In which case it's really easy!

avatar image Jasper Hesseling · Oct 30, 2011 at 01:42 PM 0
Share

Assets/Head Camera.cs(14,26): error CS0029: Cannot implicitly convert type UnityEngine.Transform' to UnityEngine.Vector3'

This is the error

avatar image syclamoth · Oct 30, 2011 at 02:03 PM 0
Share

Oh whoops. Forgot that the headlook thing tracks onto locations, not transforms. In any case, I've fixed it now.

Show more comments

1 Reply

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

Answer by syclamoth · Oct 30, 2011 at 12:28 PM

Get rid of that CursorHit thing entirely, and just set

headLook.target = Camera.main.transform.position;

wherever you have a reference to your HeadLook script!

The camera is a transform like any other object, and as such can be tracked by the head-look script.

Comment
Add comment · 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Importing Headlookcontroller into unity?? 0 Answers

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

Mecanim + HeadLookController 1 Answer

How to assign variable aim for headlookcontroller 1 Answer

How to rotate the head in the direction of the camera 2 Answers


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