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);
}
}