- Home /
Question by
JackB34 · May 07, 2020 at 04:59 PM ·
2drigidbodyplatformertime.deltatime
When In Fullscreen My Platformer Character Slows Down
I have a platformer character that does all the the normal platformer stuff. Everything works fine. The only problem is, The player slows down when I play in full screen. I have used Time.deltaTime, so don't tell me to do that. I used the player script from Jonas Tyrollers platformer video. This is the video: https://www.youtube.com/watch?v=vFsJIrm2btU
Here is the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMove : MonoBehaviour
{
[SerializeField]
LayerMask lmWalls;
[SerializeField]
float fJumpVelocity = 5;
Rigidbody2D rigid;
private Vector3 bottomOfPlayer;
float fJumpPressedRemember = 0;
[SerializeField]
float fJumpPressedRememberTime = 0.2f;
float fGroundedRemember = 0;
[SerializeField]
float fGroundedRememberTime = 0.25f;
[SerializeField]
float fHorizontalAcceleration = 1;
[SerializeField]
[Range(0, 1)]
float fHorizontalDampingBasic = 0.5f;
[SerializeField]
[Range(0, 1)]
float fHorizontalDampingWhenStopping = 0.5f;
[SerializeField]
[Range(0, 1)]
float fHorizontalDampingWhenTurning = 0.5f;
[SerializeField]
[Range(0, 1)]
float fCutJumpHeight = 0.5f;
void Start()
{
rigid = GetComponent<Rigidbody2D>();
}
void Update()
{
bottomOfPlayer = new Vector3(this.transform.position.x, (this.transform.localScale.y - this.transform.localScale.y), this.transform.position.z);
Vector2 v2GroundedBoxCheckPosition = (Vector2)transform.position + new Vector2(0, -0.01f);
Vector2 v2GroundedBoxCheckScale = (Vector2)transform.localScale + new Vector2(-0.02f, 0);
bool bGrounded = Physics2D.OverlapBox(v2GroundedBoxCheckPosition, v2GroundedBoxCheckScale, 0, lmWalls);
fGroundedRemember -= Time.deltaTime;
if (bGrounded)
{
fGroundedRemember = fGroundedRememberTime;
}
fJumpPressedRemember -= Time.deltaTime;
if (Input.GetButtonDown("Jump"))
{
fJumpPressedRemember = fJumpPressedRememberTime;
}
if (Input.GetButtonUp("Jump"))
{
if (rigid.velocity.y > 0)
{
rigid.velocity = new Vector2(rigid.velocity.x, rigid.velocity.y * fCutJumpHeight);
}
}
if ((fJumpPressedRemember > 0) && (fGroundedRemember > 0))
{
fJumpPressedRemember = 0;
fGroundedRemember = 0;
rigid.velocity = new Vector2(rigid.velocity.x, fJumpVelocity);
}
float fHorizontalVelocity = rigid.velocity.x;
fHorizontalVelocity += Input.GetAxisRaw("Horizontal");
if (Mathf.Abs(Input.GetAxisRaw("Horizontal")) < 0.01f)
fHorizontalVelocity *= Mathf.Pow(1f - fHorizontalDampingWhenStopping * Time.deltaTime, 10f);
else if (Mathf.Sign(Input.GetAxisRaw("Horizontal")) != Mathf.Sign(fHorizontalVelocity))
fHorizontalVelocity *= Mathf.Pow(1f - fHorizontalDampingWhenTurning * Time.deltaTime, 10f);
else
fHorizontalVelocity *= Mathf.Pow(1f - fHorizontalDampingBasic, Time.deltaTime * 10f);
rigid.velocity = new Vector2(fHorizontalVelocity, rigid.velocity.y);
Vector3 characterScale = transform.localScale;
if (Input.GetAxis("Horizontal") < 0)
{
characterScale.x = -0.7f;
}
if (Input.GetAxis("Horizontal") > 0)
{
characterScale.x = 0.7f;
}
transform.localScale = characterScale;
}
}
Thanks to anyone who helps.d
Comment