После прыжка персонаж зависает в воздухе и очень очень медленно спускается на землю, но если зажаты кнопки влево или вправо персонаж нормально приземляется.
Подскажите пожалуйста в чем может быть проблема.
зависания появились после добавления анимации
скрипт в спойлере
Скрытый текст:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent (typeof(CharacterController))]
public class Controller : MonoBehaviour{
private CharterController pc;
void Start(){
pc = GetComponent<CharterController> ();
}
void Update() {
if (Input.GetButtonDown("Jump"))
{
pc.Jump();
}
pc.Move(Input.GetAxis("Horizontal"));
}
}
using System.Collections.Generic;
using UnityEngine;
[RequireComponent (typeof(CharacterController))]
public class Controller : MonoBehaviour{
private CharterController pc;
void Start(){
pc = GetComponent<CharterController> ();
}
void Update() {
if (Input.GetButtonDown("Jump"))
{
pc.Jump();
}
pc.Move(Input.GetAxis("Horizontal"));
}
}
Скрытый текст:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Движение перса лево+право, поворот перса лево+право
[RequireComponent(typeof(Rigidbody2D))]
public class CharterController : MonoBehaviour
{
public float runSpeed = 10f;
public float jumpForce = 10f;
public Transform cirTarg;
public float radCir = 5f;
private Rigidbody2D rb;
Animator anim;
void Start()
{
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
bool isGround()
{
Collider2D[] gh = Physics2D.OverlapCircleAll(cirTarg.position, radCir);
int j = 0;
for (int i = 0; i < gh.Length; i++)
{
if (gh[i].gameObject != gameObject)
j++;
}
return j > 0;
}
void Update()
{
if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.LeftArrow))
{
anim.SetInteger("State", 1);
}
if (Input.GetKeyUp(KeyCode.RightArrow) || Input.GetKeyUp(KeyCode.LeftArrow))
{
anim.SetInteger("State", 0);
}
}
public void Jump()
{
if (isGround())
rb.AddForce(transform.up * jumpForce, ForceMode2D.Impulse);
}
public void Move(float ax)
{
Vector3 direction = transform.right * ax;
transform.position = Vector3.Lerp(transform.position, transform.position + direction, runSpeed * Time.deltaTime);
if ((ax > 0 && transform.localScale.x < 0) || (ax < 0 && transform.localScale.x > 0))
transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
}
}
using System.Collections.Generic;
using UnityEngine;
// Движение перса лево+право, поворот перса лево+право
[RequireComponent(typeof(Rigidbody2D))]
public class CharterController : MonoBehaviour
{
public float runSpeed = 10f;
public float jumpForce = 10f;
public Transform cirTarg;
public float radCir = 5f;
private Rigidbody2D rb;
Animator anim;
void Start()
{
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
bool isGround()
{
Collider2D[] gh = Physics2D.OverlapCircleAll(cirTarg.position, radCir);
int j = 0;
for (int i = 0; i < gh.Length; i++)
{
if (gh[i].gameObject != gameObject)
j++;
}
return j > 0;
}
void Update()
{
if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.LeftArrow))
{
anim.SetInteger("State", 1);
}
if (Input.GetKeyUp(KeyCode.RightArrow) || Input.GetKeyUp(KeyCode.LeftArrow))
{
anim.SetInteger("State", 0);
}
}
public void Jump()
{
if (isGround())
rb.AddForce(transform.up * jumpForce, ForceMode2D.Impulse);
}
public void Move(float ax)
{
Vector3 direction = transform.right * ax;
transform.position = Vector3.Lerp(transform.position, transform.position + direction, runSpeed * Time.deltaTime);
if ((ax > 0 && transform.localScale.x < 0) || (ax < 0 && transform.localScale.x > 0))
transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
}
}