简体   繁体   中英

Unity can't stop character from attaching to walls

My character in Unity is attaching to the walls of objects I put in my scene when he jumps onto them. How do I make it so he does not attach to walls? I've searched all over stackoverflow but I can't seem to find a solution that's works for me. I'm new to Unity so a "explain like I'm 5" would be really appreciated :) Here is my player controller script.

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

public class RigidbodyPlayerController : MonoBehaviour
{

    public Rigidbody playerRidgidBody;
    public float movementSpeed = 3f;
    public float jumpForce;
    public bool isGrounded;
    private float horizontalInput; 
    private float verticalInput;
    private float jumpInput;

    void Awake()
    {
        playerRidgidBody.freezeRotation = true;
        playerRidgidBody.useGravity = true;
    }
    void OnCollisionStay(){
        isGrounded = true;
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        //make caracter jump
        jumpInput = Input.GetAxis("Jump");
        if (jumpInput == 1.0 && isGrounded == true)
        {
        playerRidgidBody.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
        isGrounded = false;
        }
        
        // Move Forward/backwards
        verticalInput = Input.GetAxis("Vertical");
        transform.Translate(Vector3.forward * verticalInput * movementSpeed * Time.deltaTime);

        // Move left/right
        horizontalInput = Input.GetAxis("Horizontal");
        transform.Translate(Vector3.right * horizontalInput * movementSpeed * Time.deltaTime);
    }
}
void OnCollisionStay(Collision collision){
    isGrounded = true;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM