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 RetMenTos · Jan 28, 2020 at 11:07 AM · cameracharactercontrollermovement script

Moving camera up/down causes player to drift upwards,Up/down movement when moving camera on x axis [SOLVED]

I was working on a basic FPS controller, but i found that whenever i move my camera up/down my character will gradually move up. is there something I'm doing wrong or will I have to redo my code again? Sorry if the solution is really simple, I've only been using Unity for 5 days.

This is my code:
using System.Collections; using System.Collections.Generic; using UnityEngine; //CharacterController based FPS movement/camera script. public class ControlFPS : MonoBehaviour { //Adjustable variables public float speed = 2f; public float sensitivity = 2f; public float gravity = 1f; public Vector2 XaxisMinMax = new Vector2(50, -50); public GameObject eyes; //player CharacterController player; //movement variables float horimove; float vertmove; //Camera Y/X axis, and Player capsule's Y axis orientation float Yaxis; float Xaxis; float RotY; //Thing I use for gravity Vector3 moveDirection = Vector3.zero; //Program recognizes charactercontroller as player void Start() { player = GetComponent<CharacterController>(); } //code to collect input and rotate the player on Y axis void FixedUpdate() { //WASD movement horimove = Input.GetAxis("Horizontal") * speed * Time.deltaTime; vertmove = Input.GetAxis("Vertical") * speed * Time.deltaTime; //Camera and Capsule rotation on Y axis Yaxis += Input.GetAxis("Mouse X") * sensitivity * Time.deltaTime; RotY = Input.GetAxis("Mouse X") * sensitivity * Time.deltaTime; //Camera rotation on X axis and limit to rotation Xaxis -= Input.GetAxis("Mouse Y") * sensitivity * Time.deltaTime; Xaxis = Mathf.Clamp(Xaxis, XaxisMinMax.y, XaxisMinMax.x); //Gravity if (!player.isGrounded) { moveDirection.y -= gravity * Time.deltaTime; player.Move(moveDirection * Time.deltaTime); } //rotate player on Y axis transform.Rotate(0f, RotY, 0f); } //code to rotate the camera and move the player void LateUpdate() { //rotate camera eyes.transform.eulerAngles = new Vector3(Xaxis, Yaxis, 0f); //move the player Vector3 movement = new Vector3(horimove, 0, vertmove); movement = transform.rotation * movement; player.Move(movement); } }

Edit: Solved the issue, turns out the rigidbody component on my player capsule was causing the problem.

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

0 Replies

· Add your reply
  • Sort: 

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

192 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

Related Questions

[ C#] Character Movement based on Camera Direction. 2 Answers

How do I make my character lean to the sides? 0 Answers

How To Desync A Player's Camera? 1 Answer

Roll/Dodge/Evade System 1 Answer

Top Down Mobile Game movement (rb or CC) 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