Mail.ruПочтаМой МирОдноклассникиВКонтактеИгрыЗнакомстваНовостиКалендарьОблакоЗаметкиВсе проекты

Персонаж в юнити 2д не ходит

Потный Воронёнок Ученик (96), открыт 1 неделю назад
вот весь скрипusing System.Collections;
using System.Collections.Generic;
using System.ComponentModel.Design.Serialization;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
public Rigidbody2D rb;

private float hormove = 0f;
private bool right = true;

[Header("PlayerMovementSettings")]
[Range(0,10f)]public float speed = 5f;
[Range(0,15f)]public float jumpForce = 8f;
[Space]
[Header("Ground Checker Settings")]
public bool isgrounded = false;
[Range(-5,5f)]public float checkGroundOffsetY = -1.8f;
[Range(0,5f)]public float checkGroundRadius = 0.3f;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
}

// Update is called once per frame
void Update()
{
hormove = Input.GetAxisRaw("Horizontal")* speed;
if(hormove < 0 && right)
{
flip();
}
if(hormove > 0 && !right)
{
flip();
}
if(Input.GetKeyDown(KeyCode.Space))
{
rb.AddForce(transform.up * jumpForce,ForceMode2D.Impulse);
}
}
private void FixedUpdate()
{
Vector2 targetvelocity = new Vector2 (hormove * 10f, rb.velocity.y);
rb.velocity = targetvelocity;
}
private void flip()
{
right = !right;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
private void checkGround()
{
Collider2D[] colliders = Physics2D.OverlapCircleAll(new Vector2(transform.position.x, transform.position.y + checkGroundOffsetY),checkGroundRadius);
}
}

сначала походил, а на следующий день перестал
2 ответа
Сатору Годжо. Гуру (3837) 1 неделю назад
Мой мозг взорвался, извини
Алексей Пупок Мастер (1037) 1 неделю назад
 private void FixedUpdate() 
{
Vector2 targetVelocity = new Vector2(hormove * speed, rb.velocity.y);
rb.velocity = new Vector2(targetVelocity.x, rb.velocity.y);
}
Похожие вопросы