Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Walking through walls (Not supposed to)

Discussion in 'Editor & General Support' started by Majicateball5, Mar 17, 2019.

  1. Majicateball5

    Majicateball5

    Joined:
    Dec 12, 2015
    Posts:
    2
    Hello everyone,
    I haven't messed around with Unity in quite some time, but now I'm starting a new project using a 3d project. The problem I seem to keep running into, is that my player is able to walk right through the walls. I've tried using both, Probuilder objects, as well as native Unity Objects. Tried adding box colliders, and still no change. I'm not sure what seems to be the issue, but I would really appreciate any help. The movement script is really basic, so I don't think there's anything in there that is affecting it. I've also tried using the native Unity character controller, and I have the same issue. The character doesn't fall through the bottom, but will easily walk through the exterior barriers of the scene.

    Below is the script for the movement.

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

    public class block_trial : MonoBehaviour
    {
    public float speed = 18;

    private Rigidbody rig;

    // Start is called before the first frame update
    void Start()
    {
    rig = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
    float hAxis = Input.GetAxis("Horizontal");
    float vAxis = Input.GetAxis("Vertical");

    Vector3 movement = new Vector3(hAxis, 0, vAxis) * speed * Time.deltaTime;

    rig.MovePosition(transform.position + movement);
    }
    }


    I appreciate any help, and will update as I try the suggestions.
    Thanks,
    Daniel