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 Voridian · Feb 18, 2014 at 03:14 AM · c#fpscamera.main

fps camera facing 90 degrees the wrong way, C# coding issue.

Hey all, I'm sure this is an easy fix and I have just dome something silly but i cant find the answer on Google. I'm doing a simple fps to relearn how to use everything and for some reason the main camera is always 90 degrees left of the character model. the movement still works like the camera is pointing the right way and the pitch and yaw functionally work the fine though.

if that's not making sense, imagine if you turn your head is permanently facing to the left. here is the code and thanks for any help.

 using UnityEngine;
 using System.Collections;
 
 public class FirstPersonController : MonoBehaviour {
 
     public float movementspeed = 3.0f;
     public float strafespeed = 2.0f;
     public float mouseSensitivityH = 3.0f;
     public float mouseSensitivityV = 3.0f;
     public float pitchRange = 60.0f;
     float desiredPitch = 0;
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         //Rotation
         float rotYaw = Input.GetAxis("Mouse X") * mouseSensitivityH;
         transform.Rotate(0, rotYaw, 0);
 
         desiredPitch -= Input.GetAxis("Mouse Y") * mouseSensitivityV;
         desiredPitch = Mathf.Clamp(desiredPitch, -pitchRange, pitchRange);
         Camera.main.transform.localRotation = Quaternion.Euler(desiredPitch, 0, 0);
     
         // Movement
         float forwardSpeed = Input.GetAxis("Vertical") * movementspeed * -1;
         float sideSpeed = Input.GetAxis("Horizontal") * strafespeed;
 
         Vector3 speed = new Vector3( forwardSpeed, 0, sideSpeed);
 
         speed = transform.rotation * speed;
 
         CharacterController cc = GetComponent<CharacterController>();
 
         cc.SimpleMove( speed );
     }
 }
 
Comment
Add comment · Show 3
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 Voridian · Feb 18, 2014 at 03:49 AM 0
Share

thanks for the answer, i dont understand what you mean by "speed is Vector3, transform.rotation is Quaternion and you are mulitplying the two" sorry.

i tried moving the cc declaration to start and then into the public declarations up the top and both gave me a 'cc is not declared in current script' error.

the camera was rotated but removing the rotation did nothing.

avatar image getyour411 · Feb 18, 2014 at 03:54 AM 0
Share

For the cc, put this in your var declarations at top

 private CharacterController cc;

in Start put

 cc = GetComponent<CharacterController>();

then in Update() get rid of the line that's defining it

If you multiply a Banana * a Ford Pickup, what would you get?

avatar image Voridian · Feb 18, 2014 at 04:04 AM 0
Share

ah great that works without errors now. thanks btw: alt text

this is what you get when you multiply a Banana and a Ford Pickup

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by getyour411 · Feb 18, 2014 at 03:32 AM

Couple of general issues

1) speed is Vector3, transform.rotation is Quaternion and you are mulitplying the two

2) Move the cc declaration out of Update() so that it doesn't have to do that every frame

3) if your camera is a child of the player, make sure it hasn't been rotated

Glad you got it sorted out (and kudos on the pic) I'll change this to an answer.

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 Voridian · Feb 18, 2014 at 04:17 AM 0
Share

only problem now is that for some reason the editer preview shows that the camera is facing backwards but in the game window thingy its facing the right way... Edit: wait never$$anonymous$$d i got it ^^;

avatar image getyour411 · Feb 20, 2014 at 08:29 PM 0
Share

If you happen to see this again, please click Accept Solution to close this.

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

19 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

Related Questions

Multiple Cars not working 1 Answer

error CS1061 anybody might help me? 1 Answer

Distribute terrain in zones 3 Answers

C# how to have a part of an object rotate while animation is being played 2 Answers

How to draw an arrow from fps contoller 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