Hi every one. I have a player without a rigidbody but with a collider. I want it to stop when hitting a wall. the wall also has a collider but my player just goes through the wall like its nothing. can somebody help me? thank you.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovment : MonoBehaviour
{
public float speed = 5f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
{
transform.position += transform.forward * Time.deltaTime * speed;
}
if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
{
transform.position += transform.right * Time.deltaTime * speed;
}
if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
{
transform.position += -transform.forward * Time.deltaTime * speed;
}
if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
{
transform.position += -transform.right * Time.deltaTime * speed;
}
Camera.main.transform.localEulerAngles += new Vector3(-Input.GetAxis("Mouse Y"), Input.GetAxis("Mouse X"), 0);
}
}
Giving the objects colliders and rigidbodies and then moving them by setting velocity can STILL move the objects through each other. How to prevent this?
– KokodokoGames