- Home /
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);
}
}
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.
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
![](https://koobas.hobune.stream/wayback/20220613162200im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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