Код (незаконченный):
Код: Выделить всё
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public Vector2 Velocity, WallJumpForce;
public float Acceleration, Decceleration;
public float Gravity, JumpForce;
public int TargetFPS;
void Update()
{
Velocity.y -= Gravity;
if(Input.GetKey("right") || Input.GetKey("d"))
Velocity.x += Acceleration * SDT();
if(Input.GetKey("left") || Input.GetKey("a"))
Velocity.x -= Acceleration * SDT();
Velocity.x -= Velocity.x*(1-Decceleration) * SDT();
Move(Velocity.x, 0);
Debug.Log(1 / Time.deltaTime + ", " + SDT());
Application.targetFrameRate = TargetFPS;
}
void Move(float x, float y) //Converts Scratch Units to Unity Units
{
transform.position += new Vector3(x, y, 0) * 1.2f * Time.deltaTime;
}
float SDT() //Basically allows Scratch variables designed for 30fps work in unity
{
return 30 * Time.deltaTime;
}
}
на
Код: Выделить всё
Velocity.x -= Velocity.x*(1-Decceleration) * SDT();Для справки: это игра, которую я портирую.
https://scratch.mit.edu/projects/590825095
Подробнее здесь: https://stackoverflow.com/questions/725 ... -deltatime
Мобильная версия