i can't figure out how to check for collision, here is my camera-movement script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class cameracontroller : MonoBehaviour
{
public float movementSpeed;
public float movementTime;
public Vector3 newPosition;
// Start is called before the first frame update
void Start()
{
newPosition = transform.position;
}
// Update is called once per frame
void Update()
{
HandleMovementInput();
}
void HandleMovementInput()
{
if(Input.GetKey(KeyCode.W))
{
newPosition += (transform.forward * movementSpeed);
}
if(Input.GetKey(KeyCode.S))
{
newPosition += (transform.forward * -movementSpeed);
}
if(Input.GetKey(KeyCode.D))
{
newPosition += (transform.right * movementSpeed);
}
if(Input.GetKey(KeyCode.A))
{
newPosition += (transform.right * -movementSpeed);
}
transform.position = Vector3.Lerp(transform.position, newPosition, Time.deltaTime * movementTime);
}
}
I've tried using void OnCollisionEnter(Collision collision)
but didn't seem to work, am i doing something wrong? All object have colliders and i have also tried using rigidbody. I am still a beginner programmer and only code in my spare time, to explain my lack of knowledge.