У меня есть небольшая проблема с этой игрой, в которой я работаю, проблема в том, что объект игрока не вращается с кодом, который я использую, и раньше он работал, IDK почему, он работал хорошо и я проверил несколько раз, очень просто вот код.
Редактировать. Я только что опубликовал весь код контроллера
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
private Rigidbody2D rb;
public float speed;
public float runSpeed;
public float jumpForce;
private float moveInput;
private Vector3 rotation;
public bool isGrounded;
private bool isAlsoTrampoline;
public Transform feetPos;
public float checkRadius;
public LayerMask whatIsGround;
private Animator animator;
private float jumpTimeCounter;
public float jumpTime;
private bool isJumping;
private int cState = 1;
private int capsState = 1;
public bool isWalking;
public bool isRunning;
public bool isCrunching;
public bool isSliding;
public bool isGraping;
public Vector3 climbPos;
private PortalDetector portalName;
private Transform otherPortal;
private int colorPortal = 0;
private GameObject otherPortalPos;
private Vector2 currentY,lastY;
private AudioSource audioStep;
private bool amFalling;
public void Step()
{
audioStep.Play();
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "Trampoline")
{
isAlsoTrampoline = true;
}
if (collision.tag == "Ledge")
{
Debug.Log("Puedo Trepar esto!!??? ");
if (!isGrounded)
{
isGraping = true;
rb.gravityScale = 0;
rb.velocity = new Vector3(0,0,0);
animator.SetBool("isLedge", true);
climbPos = GetComponent<Transform>().position;
Debug.Log("Trepado!!!!!:DDDDD");
}
}
if (collision.tag == "BluePortal")
{
colorPortal = 1;
}
else if (collision.tag == "OrangePortal")
{
colorPortal = 2;
}
if (collision.tag == "Transporter")
{
if (colorPortal == 1)
{
otherPortal = collision.gameObject.transform.GetChild(3);
}
if (colorPortal == 2)
{
otherPortal = collision.gameObject.transform.GetChild(2);
}
otherPortalPos = otherPortal.transform.gameObject;
transform.position = new Vector3(otherPortalPos.transform.position.x, otherPortalPos.transform.position.y, transform.position.z);
rb.velocity = new Vector3(0, 0, 0);
}
}
void BackToIdle()
{
GetComponent<Rigidbody2D>().velocity = new Vector3(climbPos.x+5,climbPos.y,climbPos.z);
GetComponent<Rigidbody2D>().gravityScale = 10;
animator.SetBool("isLedge", false);
isGraping = false;
}
void ClimbingStepOne()
{
GetComponent<Rigidbody2D>().velocity = new Vector3(climbPos.x, climbPos.y + 5, climbPos.z);
}
void Start()
{
portalName = GetComponent<PortalDetector>();
rb = GetComponent<Rigidbody2D>();
animator = GetComponent<Animator>();
audioStep = GetComponent<AudioSource>();
currentY = lastY;
}
// Update is called once per frame
void FixedUpdate()
{
if (isGrounded && !isGraping)
{
if (isWalking)
{
moveInput = Input.GetAxisRaw("Horizontal");
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
}
if (isCrunching)
{
moveInput = Input.GetAxisRaw("Horizontal");
rb.velocity = new Vector2(moveInput * (speed - 1), rb.velocity.y);
}
}
if (isRunning && !isCrunching && !isGraping)
{
moveInput = Input.GetAxisRaw("Horizontal");
rb.velocity = new Vector2(moveInput * runSpeed, rb.velocity.y);
}
if (isRunning && isSliding && !isGraping)
{
moveInput = Input.GetAxisRaw("Horizontal");
rb.velocity = new Vector2(moveInput * runSpeed, rb.velocity.y);
}
}
void Update()
{
isGrounded = Physics2D.OverlapCircle(feetPos.position, checkRadius, whatIsGround);
currentY = new Vector2(transform.position.x, transform.position.y);
if (Input.GetKey(KeyCode.UpArrow) && isGraping)
{
animator.SetBool("isClimbing", true);
}
if (!isGrounded && isAlsoTrampoline)
{
animator.SetBool("isFalling", true);
}
else
{
isAlsoTrampoline = false;
animator.SetBool("isFalling", false);
}
if (Input.GetKeyUp(KeyCode.CapsLock) && !isCrunching)
{
capsState *= -1;
if (capsState < 0 && moveInput == 0)
{
isWalking = false;
isRunning = true;
jumpForce = 14f;
}
else if(capsState > 0 && moveInput == 0)
{
isWalking = true;
isRunning = false;
jumpForce = 7f;
}
else if (capsState < 0 && moveInput != 0)
{
isWalking = false;
isRunning = true;
animator.SetBool("isRunning", true);
animator.SetBool("isWalking", false);
jumpForce = 14f;
}
else if (capsState > 0 && moveInput != 0)
{
isWalking = true;
isRunning = false;
animator.SetBool("isRunning", false);
animator.SetBool("isWalking", true);
jumpForce = 7f;
}
}
if (moveInput > 0)
{
transform.eulerAngles = new Vector3(0, 0, 0);
}
else if (moveInput < 0)
{
transform.eulerAngles = new Vector3(0, 180, 0);
}
if (moveInput == 0)
{
animator.SetBool("isWalking", false);
animator.SetBool("isRunning", false);
}
else
{
if (isWalking)
{
animator.SetBool("isWalking", true);
}
if (isRunning)
{
animator.SetBool("isRunning", true);
}
}
if(isGrounded && Input.GetKeyUp(KeyCode.C))
{
cState *= -1;
if (isRunning)
{
if (cState < 0)
{
StartCoroutine (IsSliding());
cState *= -1;
}
else if (cState > 0)
{
StartCoroutine(IsSliding());
cState *= -1;
}
}
else
{
isRunning = false;
isWalking = true;
if (cState < 0)
{
animator.SetBool("isCrunching", true);
isCrunching = true;
}
else if (cState > 0)
{
animator.SetBool("isCrunching", false);
isCrunching = false;
}
}
}
if (isGrounded && Input.GetKeyDown(KeyCode.Space))
{
isJumping = true;
jumpTimeCounter = jumpTime;
rb.velocity = Vector2.up * jumpForce;
animator.SetTrigger("takeOf");
}
if (isGrounded)
{
animator.SetBool("onGround", true);
animator.SetBool("isFalling", false);
amFalling = false;
}
else
{
if ((currentY.y < lastY.y - 2) && amFalling == false)
{
lastY = currentY;
animator.SetBool("isFalling", true);
amFalling = true;
}
animator.SetBool("onGround", false);
}
if (Input.GetKey(KeyCode.Space) && isJumping == true)
{
if (jumpTimeCounter > 0)
{
rb.velocity = Vector2.up * jumpForce;
jumpTimeCounter -= Time.deltaTime;
}
else
isJumping = false;
}
if (Input.GetKeyUp(KeyCode.Space))
{
isJumping = false;
}
}
IEnumerator IsSliding()
{
isSliding = true;
isRunning = true;
isWalking = false;
animator.SetBool("isCrunching", true);
yield return new WaitForSecondsRealtime(.5f);
animator.SetBool("isCrunching", false);
animator.SetBool("isRunning", true);
isSliding = false;
}
}
Я только что создал файл debug.log, и вот результат
Перемещение входного значения: 1 Перемещение вправо, eulerAngle: (0.0, 0.0 , 0.0) вращение: (0.0, 0.0, 0.0, 1.0) UnityEngine.Debug: Log (Object) PlayerController: Update () (в разделе «Ресурсы / сценарии / PlayerController.cs: 210)
Перемещение входного значения: - 1 Перемещение влево, eulerAngle: (0,0, 180,0, 0,0) вращение: (0,0, 1,0, 0,0, 0,0) UnityEngine.Debug: Log (Object) PlayerController: Update () (в ресурсах / скриптах / PlayerController.cs: 215)