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 /
  • Help Room /
avatar image
0
Question by QuincyOnIce · Apr 01, 2020 at 12:31 PM · unity 5bugbuild-error

Player moves slower when moving camera in build, but not in editor.

Hello, I built my game after just testing stuff in the editor after a while, and a strange issue arose. When I move the camera in-game, the character moves slower.

Here's what I'm talking about:


In-Editor: https://media.giphy.com/media/L0AnuLX33Xb8Pqvaz0/giphy.gif (Good)

Built: https://media.giphy.com/media/WnCDwYhj4pu5Auzv96/giphy.gif (Bad)


I have no Idea why it'd do this, as the editor one works fine. The physics start behaving weirdly too. There's no "#if UNITY_EDITOR" block anywhere in the code, so I'm honestly clueless.

Any theories would be great :(


Here's my code for movement:


 #region References
     [SerializeField]
     Camera CAM; //Def FOV = 60, Sprint = 75
     [SerializeField]
     Keybinds KB;
     Rigidbody RB;
 #endregion
 
     [SerializeField]
     float RunSpeed, SprintSpeed, JumpForce, MaxJumpCount;
     float Horizontal, Vertical;
         
     public float JumpCount = 0;
 
     public bool CanMove;
     public bool CanDoubleJump;
     public bool OnGround;
 
     Vector3 DirectionVector;
 
     private void Start()
     {
         CanMove = true;
 
         RB = GetComponent<Rigidbody>();
     }
 
     void Update()
     {
         if ( CanMove ) { Move(); }
     }
 
     private void LateUpdate()
     {
         Jump();
     }
 
     void Move()
     {
         
         Horizontal = Input.GetAxis("Horizontal"); Vertical = Input.GetAxis("Vertical");
 
         DirectionVector.x = Horizontal; DirectionVector.z = Vertical;
         DirectionVector = Vector3.ClampMagnitude(DirectionVector, 1f);
 
         if ( !Input.GetKey(KB.Sprint) )
         {
             CAM.fieldOfView = Mathf.Lerp(CAM.fieldOfView, 60, 0.1f);
             RB.MovePosition(transform.position + transform.TransformDirection(DirectionVector * RunSpeed * Time.deltaTime));
         }
         else
         {
             CAM.fieldOfView = Mathf.Lerp(CAM.fieldOfView, 90, 0.1f);
             RB.MovePosition(transform.position + transform.TransformDirection(DirectionVector * SprintSpeed * Time.deltaTime));
         }
     }
 
     void Jump()
     {
         if ( Input.GetKeyDown(KB.Jump) && JumpCount < MaxJumpCount)
         {
             if (DirectionVector.sqrMagnitude == 0  && OnGround) //Jump extra high when not moving
             {
                 RB.AddForce(((transform.up * 2) + transform.TransformDirection(DirectionVector)) * JumpForce, ForceMode.Impulse);
                 JumpCount++;
             }
             else
             {
                 if ( OnGround ) //Extra boost when double jumping
                 {
                     RB.AddForce((transform.up + transform.TransformDirection(DirectionVector)) * JumpForce, ForceMode.Impulse);
                     JumpCount++;
                 }
                 else
                 {
                     RB.AddForce((transform.up + transform.TransformDirection(DirectionVector)) * JumpForce * 1.5f, ForceMode.Impulse);
                     JumpCount++;
                 }
             }
         }
     }
 
     private void OnCollisionEnter( Collision Collision )
     {
         if (Collision.collider.gameObject.layer == 8 )
         {
             OnGround = true; JumpCount = 0;
             RB.velocity = Vector3.zero;
         }
     }
 
     private void OnCollisionExit( Collision Collision )
     {
         if ( Collision.collider.gameObject.layer == 8 )
         {
             OnGround = false;
         }
     }
 }   



And Here's my Code for the Camera control:


 #region References
     [SerializeField]
     Keybinds KB;
     #endregion
 
     [SerializeField]
     Transform Target, Player;
     //Transform Obstruction = null;
 
     [SerializeField]
     float Sensitivity, CameraMaxAngle, CameraMinAngle;
     float MouseX, MouseY; //ZoomSpeed;
 
     public bool CanRotate;
 
     private void Start()
     {
         CanRotate = true;
 
         Cursor.visible = false;
         Cursor.lockState = CursorLockMode.Locked;
     }
 
     private void Update()
     {
         CameraControl();
         //ViewObstructed();
     }
 
     void CameraControl()
     {
         MouseX += Input.GetAxis("Mouse X") * Sensitivity * Time.deltaTime;
         MouseY -= Input.GetAxis("Mouse Y") * Sensitivity * Time.deltaTime;
         MouseY = Mathf.Clamp(MouseY, CameraMinAngle, CameraMaxAngle);
 
         transform.LookAt(Target);
 
         Target.rotation = Quaternion.Slerp(Target.rotation, Quaternion.Euler(MouseY, MouseX, 0), 0.5f);
         if ( !Input.GetKey(KB.LockPlayerRotation) && CanRotate ) 
         {
             Player.rotation = Quaternion.Slerp(Player.rotation, Quaternion.Euler(0, MouseX, 0), 0.5f);
         }
     }



If you have any clue, but need more details, please say so.

[1]: https://gph.is/g/ZrdgPbx

[2]: https://gph.is/g/E1W3AVD

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
0

Answer by MarioDude3 · Jun 26, 2020 at 04:37 PM

I have the same issue to its so weird my new game doesn't even work on newgrounds as you REQUIRE speed but it works fine in the editor

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

308 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

Related Questions

Game crashes on iPhone 11 0 Answers

Materials Broken When Downgrading from 5.6 to 5.5 0 Answers

unable to get build for iPhone from Xcode 7 Answers

Problems after Open Unity 5 project with Unity 4 3 Answers

Unity after update won't let me build my game 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