hi ,
I made a 2d game , it’s responsive for all resolutions , but the player runs slower in high resolutions , I tried addid * Time.deltaTime to velocity but it didn’t fixed it completly . I want it to have the same speed for all resolutions
it runs and jumps slower in : 1920x1080
my code :
void Start () {
rb2d = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
soundz = GetComponent<AudioSource> ();
spd = GetComponent<Rigidbody2D>();
Cloud = GameObject.Find("Cloud");
// rb2d.velocity *= mycam.orthographicSize * 1,
//cloudanim = GameObject.Find("Cloud(Clone)").GetComponent<Animator>();
}
void OnCollisionEnter2D(Collision2D collision2D) {
if (collision2D.relativeVelocity.magnitude > 20){
Boost = Instantiate(Resources.Load("Prefabs/Cloud"), transform.position, transform.rotation) as GameObject;
// cloudanim.Play("cloud");
}
}
// Update is called once per frame
void Update () {
if (Input.GetButtonDown("Jump") && (isGrounded || !doubleJump))
{
soundz.Play ();
rb2d.AddForce(new Vector2(0,jumpForce));
//rb2d.velocity *= mycam.orthographicSize * 0.11f;
if (!doubleJump && !isGrounded)
{
doubleJump = true;
Boost = Instantiate(Resources.Load("Prefabs/Cloud"), transform.position, transform.rotation) as GameObject;
// cloudanim.Play("cloud");
}
}
//float vert = Input.GetAxis ("Vertical") * Time.deltaTime;
if (Input.GetButtonDown("Vertical") && !isGrounded)
{
rb2d.AddForce(new Vector2(0,-jumpForce));
Boost = Instantiate(Resources.Load("Prefabs/Cloud"), transform.position, transform.rotation) as GameObject;
//cloudanim.Play("cloud");
}
if (isGrounded)
doubleJump = false;
float hor = Input.GetAxis ("Horizontal") * maxSpeed * Time.deltaTime;
anim.SetFloat ("Speed", Mathf.Abs (hor));
rb2d.velocity = new Vector2 (hor * maxSpeed * Time.deltaTime, rb2d.velocity.y );
isGrounded = Physics2D.OverlapCircle (groundCheck.position, 0.15F, whatIsGround);
anim.SetBool ("IsGrounded", isGrounded);
if ((hor > 0 && !lookingRight)||(hor < 0 && lookingRight))
Flip ();
anim.SetFloat ("vSpeed", spd.velocity.y);
}
public void Flip()
{
lookingRight = !lookingRight;
Vector3 myScale = transform.localScale;
myScale.x *= -1;
transform.localScale = myScale;
}