Unity c# - 防止玩家攀爬碰撞

时间:2020-12-25 12:49:10

标签: c# unity3d visual-studio-code

所以我有游戏,但是当我向物体(如岩石)添加碰撞时,我的角色开始爬上它......或者有时角色开始晃动(好像它想爬上它,但可以't) 当与某些自定义形状对象发生碰撞时。我不要这个。我只想让玩家在地面上移动。我一直在寻找这个,但没有找到任何有用的东西。感谢您提供任何提示! (我是 unity 和 c# 的新手) 这是我的移动(+旋转)脚本:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SharkMovement : MonoBehaviour
{
    private Rigidbody rb;
    float xInput;
    float zInput;
    public float moveSpeed;
    public float rotateSpeed;
    private Vector3 direction;
    private Vector3 fwd;
    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        // Pohyb ryby
        xInput = Input.GetAxis("Horizontal2");
        zInput = Input.GetAxis("Vertical2");
        //Zakáže pohyb dozadu - povoleno pouze vpřed,vlevo, vpravo
        zInput = Mathf.Clamp01(zInput);
        // Výpočet směru
        direction = Vector3.zero + (xInput * transform.right) + (zInput * transform.forward) ;

        if (direction != Vector3.zero)
        {
            transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(direction), rotateSpeed * Time.deltaTime);
        }
        // Posun
        rb.MovePosition(transform.position + moveSpeed * Time.deltaTime * direction);

    }
}

以下是播放器的组件: enter image description here

0 个答案:

没有答案