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 Vire · Sep 03, 2014 at 02:36 AM · c#framerate

Having a Light makes Character Controller jump higher on Mobiles

Erm.. Yeah, it doesn't make sense but that's how it is. If there is a light in my scene, the character then jumps a lot higher when on a mobile device rather than the desktop computer I'm developing on. It's not related to the frame rate because it's being multiplied by deltaTime. Seems to be a similar case for particles so obviously the frame rate is having an effect but that means delta time doesn't work correctly.

 {
     public float moveSpeed = 5.0f;
     public float turnSpeed = 5.0f;
     public float jumpSpeed = 20.0f;
     public float gravity = 0.8f;
     public float cameraFollowSpeed = 5.0f;

     public EasyJoystick joystick;
     public EasyButton jumpButton;
     public EasyButton shootButton;
     public EasyButton dunkButton;

     private Vector3 moveVector = Vector3.zero;
     private Quaternion desiredRotation = Quaternion.identity;
     private float deadZone = 0.2f; // dead-zone for joysticks
     private CharacterController characterController;
     private Animator animator;

     void Awake()
     {
         characterController = gameObject.GetComponent<CharacterController>();
         animator = gameObject.GetComponentInChildren<Animator>();
     }

     void Update()
     {
         if (characterController.isGrounded)
         {
             moveVector = Vector3.zero;
             ProcessMovement(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), joystick.JoystickAxis.x, joystick.JoystickAxis.y);

             //animator.SetFloat("Speed", moveVector.magnitude);
             
             moveVector = Camera.main.transform.TransformDirection(new Vector3(moveVector.x, 0.0f, moveVector.z)); // move relative to camera facing direction   
             moveVector *= moveSpeed;

             if (Input.GetButton("Jump") || jumpButton.buttonState == EasyButton.ButtonState.Press)
             {
                 Jump();
             }            
         }
         else
         {
             ProcessGravity();
         }

         characterController.Move(moveVector * Time.deltaTime); // move the character
         
         if (moveVector.x > deadZone || moveVector.x < -deadZone || moveVector.z > deadZone || moveVector.z < -deadZone) // only calculate rotation if there is input
         {
             desiredRotation = Quaternion.LookRotation(new Vector3(moveVector.x, 0.0f, moveVector.z));
             transform.rotation = Quaternion.Lerp(transform.rotation, desiredRotation, turnSpeed * Time.deltaTime);
         }
     }

     void ProcessMovement(float h, float v, float ht, float vt)
     {
         if (h > deadZone || h < -deadZone || v > deadZone || v < -deadZone)
         {
             moveVector = new Vector3(h, 0.0f, v);
         }
         
         if (ht > deadZone || ht < -deadZone || vt > deadZone || vt < -deadZone)
         {
             moveVector = new Vector3(ht, 0.0f, vt);
         }

         if (moveVector.magnitude > 1.0f) // diagonal inputs should be normalized
         {
             moveVector.Normalize();
         }
     }

     void ProcessGravity()
     {
         moveVector -= new Vector3(0.0f, gravity, 0.0f);
     }

     void Jump()
     {
         moveVector = new Vector3(moveVector.x, jumpSpeed, moveVector.z);
     }
 }
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 kacyesp · Sep 03, 2014 at 02:41 AM

It does have to do with frame rate.

Change this line:

     moveVector *= moveSpeed;

to

     moveVector += moveSpeed;

Think of your moveVector in terms of meters per second. Think of moveSpeed the same way. moveVector moveSpeed = m/s m/s = m^2 / s^2 Then multiplying those units my Time.deltaTime gives m^2 / s^2 * s = m^2 / s

What you really want is just meters. So it makes sense to add moveSpeed to moveVector rather than multiplying it.

Comment
Add comment · Show 1 · 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 Vire · Sep 05, 2014 at 05:18 AM 0
Share

It does have to do with frame rate but your answer isn't relevant as that occurs before the gravity and jump calculations. Just had to multiply the gravity by deltaTime as well prior to moving the character.

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

23 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How would I make a timer frame independent? 1 Answer

Making a bubble level (not a game but work tool) 1 Answer

How can I make android app run with less than 20 fps 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