Preventing glitching through colliders

I’m making an open world city game, and have began implementing planes to fly around. However the plane controller script makes the planes colliders be able to just glitch through other colliders. I’m pretty sure this is because I’m using this to move the plane in the direction its facing:

transform.position = transform.position + (transform.forward * currentForwardSpeed * Time.deltaTime * -1);

This line of code just makes the plane move forward, without accounting for any object in front, making it glitch through colliders. Is there different way of moving the plane so that it interacts with other colliders, while still being able to fly like it would in this script (I assume it would be physics based, and not simply changing the objects position, but I don’t know how to do that)?

The solution may be simple, but I’m fairly new, and have only been working in 3d for a few weeks, so I don’t have a clue what I’m doing.

Here is my full script just in case:

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

public class ShipController : MonoBehaviour
{
    public float forwardSpeed = 25f, turnSpeed = 7.5f;
    public float currentForwardSpeed;
    public float forwardAccel = 2.5f, turnAccel = 2f;

    collisionCheck check; //has bool isTouching to check if ship is touching any other colliders

    public float lookRotateSpeed = 90f;
    private Vector2 lookInput, screenCentre, mouseDistance;
    
    void Start()![189548-shipglitch.png|409x380](upload://k0g4dlGXi58wUfDqyG9pW5lblnW.png)
    {
        check = this.gameObject.GetComponent<collisionCheck>();
        screenCentre.x = Screen.width * 0.5f;
        screenCentre.y = Screen.height * 0.5f;
    }

    // Update is called once per frame
    void Update()
    {
        lookInput.x = Input.mousePosition.x;
        lookInput.y = Input.mousePosition.y;

        mouseDistance.x = (lookInput.x - screenCentre.x) / screenCentre.y;
        mouseDistance.y = (lookInput.y - screenCentre.y) / screenCentre.y;

        mouseDistance = Vector2.ClampMagnitude(mouseDistance, 1f);

        transform.Rotate(mouseDistance.y * lookRotateSpeed * Time.deltaTime, mouseDistance.x * lookRotateSpeed * Time.deltaTime, 0f, Space.Self);

        currentForwardSpeed = Mathf.Lerp(currentForwardSpeed, Input.GetAxisRaw("Vertical") * forwardSpeed, forwardAccel * Time.deltaTime);
        
        this.GetComponent<Rigidbody>().useGravity = false;
        transform.position = transform.position + (transform.forward * currentForwardSpeed * Time.deltaTime * -1);
        if (Input.GetKey(KeyCode.A))
        {
            transform.Rotate(0, 0, turnSpeed * Time.deltaTime * -1);
        }
        if (Input.GetKey(KeyCode.D))
        {
            transform.Rotate(0, 0, turnSpeed * Time.deltaTime);
        }
    }
}

I’m assuming what you want is to move forward automatically, and left and right from keyboard keys “a” and “d”. would try using transform.Translate (whatever direction) instead of transform.position. Translate will react and collide with other colliders, so long as it is not kinematic. Something similar to this:

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

public class Flight : MonoBehaviour
{

    public float speed;
    public float rotSpeed;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        transform.Translate(Vector3.forward * speed * Time.deltaTime);
        transform.Rotate(0, Input.GetAxis("Horizontal") * rotSpeed * Time.deltaTime, 0);
    }
}

Input.GetAxis(“Horizontal)” and Input.GetAxis(“Vertical”) is automatically set to control things based on the a and d, and w and s keys respectively, as well as left and right, and up and down.