Добрый день, как можно реализовать отталкивание от стен при прыжке персонажа вот код самого персонажа
Код
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Slim : MonoBehaviour
{
public float speed;
public float jumpForce;
private float moveInput;
private Rigidbody2D rb;
private bool facingRight = true;
public bool isGrounded;
public Transform groundCheck;
public float checkRadius;
public LayerMask whatIsGround;
private int extraJumps;
public int extraJumpsValue;
private void Start()
{
extraJumps = extraJumpsValue;
rb = GetComponent<Rigidbody2D>();
}
private void FixedUpdate()
{
isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);
moveInput = Input.GetAxis("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;
}
public void Update()
{
if (isGrounded == true)
{
extraJumps = extraJumpsValue;
}
if (Input.GetKeyDown(KeyCode.Space) && extraJumps > 0)
{
rb.velocity = Vector2.up * jumpForce;
extraJumps--;
}
else if (Input.GetKeyDown (KeyCode.Space) && extraJumps == 0 && isGrounded == true)
{
rb.velocity = Vector2.up * jumpForce;
}
}
void OnCollisionEnter2D(Collision2D co)
{
// Collided with a V?
if (co.collider.name == "V")
{
// Reset Rotation, Gravity, Velocity and go to last Checkpoint
transform.rotation = Quaternion.identity;
rb.gravityScale = Mathf.Abs(rb.gravityScale);
rb.velocity = Vector2.zero;
}
}
}