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 emoney101skeleton · Sep 16, 2020 at 05:22 PM · scripting problemmovementscript.movement script

The Camera is facing backwards of the Character

I don't know why but the camera is Not facing the same way as the Model any Help?

The Model Is Facing the Right Way

But Here's what It Looks Like

alt text

Yeah its facing backwards I Don't Know If Its The Code

 using UnityEngine;
 
 public class FPSFirstPerson : MonoBehaviour
 {
     
     public Transform camera;
     public Rigidbody rb;
 
     public float camRotationSpeed = 5f; 
     public float cameraMinimumY = -60f;
     public float cameraMaximumY = 75f;
     public float rotationSmoothSpeed = 10f;
 
     public float walkSpeed = 9f;
     public float runSpeed = 14f;
     public float maxSpeed = 20f; 
     public float jumpPower = 30f;
 
     public float _extraGravity = 45;
 
     float bodyRotationX; 
     float camRotationY;
     Vector3 directionIntentX;
     Vector3 directionIntentY;
     float speed;
 
     public bool grounded;
 
     void Update()
     {
         LookRotation();
         Movement();
         extraGravity();
         GroundCheck();
         if(grounded && Input.GetButtonDown("Jump"))
         {
             Jump();
         }
 
     }
 
     void LookRotation()
     {
         Cursor.visible = false;
         Cursor.lockState = CursorLockMode.Locked;
 
         bodyRotationX += Input.GetAxis("Mouse X") * camRotationSpeed;
         camRotationY += Input.GetAxis("Mouse Y") * camRotationSpeed;
 
         camRotationY = Mathf.Clamp(camRotationY, cameraMinimumY, cameraMaximumY);
 
 
         Quaternion camTargetRotation = Quaternion.Euler(-camRotationY, 0, 0);
         Quaternion bodyTargetRotation = Quaternion.Euler(0, bodyRotationX, 0);
 
 
         transform.rotation = Quaternion.Lerp(transform.rotation, bodyTargetRotation, Time.deltaTime * rotationSmoothSpeed);
 
         camera.localRotation = Quaternion.Lerp(camera.localRotation, camTargetRotation, Time.deltaTime * rotationSmoothSpeed);
     }
 
     void Movement() 
     {
 
         directionIntentX = camera.right;
         directionIntentX.y = 0;
         directionIntentX.Normalize();
 
         directionIntentY = camera.forward;
         directionIntentY.y = 0;
         directionIntentY.Normalize();
 
         rb.velocity = directionIntentY * Input.GetAxis("Vertical") * speed + directionIntentX * Input.GetAxis("Horizontal") * speed + Vector3.up * rb.velocity.y;
         rb.velocity = Vector3.ClampMagnitude(rb.velocity, maxSpeed);
 
 
         if(Input.GetKey(KeyCode.LeftShift))
         {
             speed = runSpeed;
         }
         if(!Input.GetKey(KeyCode.LeftShift))
         {
             speed = walkSpeed;
         }
 
 
     }
 
     void extraGravity()
     {
         rb.AddForce(Vector3.down * _extraGravity );
     }
 
     void GroundCheck()
     {
         RaycastHit groundHit;
         grounded = Physics.Raycast(transform.position, -transform.up, out  groundHit, 1.25f);
     }
 
     void Jump()
     {
         rb.AddForce(Vector3.up * jumpPower, ForceMode.Impulse);
     }
 }

ifg.png (210.9 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Camden9 · Sep 16, 2020 at 05:57 PM

It is most likely something small like a - (or its positive when it should be negative) somewhere on your camera's transform or rotation in your script. are they both facing the correct direction in your scene before you press play, then it turns around? or is it backwards in the editor too? But I am saying all this as someone who doesn't know a lot, just trying to help if I can!

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 emoney101skeleton · Sep 16, 2020 at 06:34 PM 0
Share

I Did Correct my Character Facing the Z Axis For the Animation Could Work So $$anonymous$$y Character is Fine. Yes, When I press play they both go separate directions, But the camera just faces the opposite Direction

avatar image Camden9 emoney101skeleton · Sep 17, 2020 at 06:24 PM 0
Share

So I started a test project with a capsule, a camera, and your code on it to hopefully better find the issue. I noticed a couple things, one issue is that when dealing with your clamping your camera, you are clamping the y rotation, when you should be clamping the X (X rotation on the camera deals with looking up and down, Y is side to side) Also I can't find anywhere in the script that you are rotating the camera to match the body rotation, which is why your camera is looking backwards. The way that you wrote the script is good, but I think that you just missed a few points, I would recommend following a tutorial on fps camera in unity, (there are like a billion) then going back to this script and trying to make it work! I would urge you to try to fix this script though, because finding what you did wrong and fixing it will teach you a lot!

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

309 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Slime script? 1 Answer

How to I put a speed limit on my character's movement? 1 Answer

Smooth jump script? 1 Answer

Question about moving an object technique 3 Answers

How do i maintain the same speed in the air? 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