Создал скрипт для передвижения игрока. При прыжке игрока телепортирует в сторону.
https://skr.sh/vHMZz06P87S
видео как это выглядит
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.SceneManagement;
using YG;
public class playerMovement : MonoBehaviour {
private Rigidbody2D rb;
private float moveInput;
private bool facingRight = true;
private bool isGrounded;
public Transform feetPos;
public float checkRadius;
public LayerMask whatIsGround;
public float jumpForce;
public float speed;
public Animator playerAnimator;
private void Awake() {
rb = GetComponent<Rigidbody2D>();
}
private void Update() {
isGrounded = Physics2D.OverlapCircle(feetPos.position, checkRadius, whatIsGround);
if(isGrounded == true && Input.GetKeyDown(KeyCode.Space)){
rb.velocity = Vector2.up * jumpForce;
}
}
private void FixedUpdate() {
moveInput = Input.GetAxisRaw("Horizontal");
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
if(facingRight == false && moveInput > 0){
Flip();
}else if(facingRight == true && moveInput < 0){
Flip();
}
}
void Flip(){
facingRight = !facingRight;
Vector3 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
}
}