Moving Object by Pressing Buttons Using NavMesh

Hello!
Currently I am working on a project and I want to move the car. Inside the car there are buttons as can be seen in the image. When a user presses a button he needs to go to the location with the same letter.

I have created a NavMesh as seen in the other image over which the car should move.

My question is, how do I create a button that sends the car to the right location on the NavMesh? Currently the buttons are just 3D objects/cubes.

Not sure if this is all the information you need :slight_smile: I have barely any experience with coding so I could really use some help!

Thank you!

I am a noob, but what I would do is a ray cast, and use this hit.collision information to move from there

Something Like this:

Something like this;

Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    RaycastHit hit;

    if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask))
       {
          UnitScriptName raycastHitUnitReference = hit.collider.gameObject.GetComponent<UnitScriptName>();         
       }

Note; add A script on each one of those boxes called UnitScriptName, also add a trigure collider on them.

Just a noob here, but thats where I would start

Hi! Thanks for your reply, so basically I add “hitboxes” with collisions on the point where I want the car to go, and then check if along the way the car hits the box that has the right letter to make it stop?

In the code you are using Input.mousePosition, this relates to where the person clicks right? Would this work for the buttons in the car?

Thank again!

Actually I was just talking about how to press the buttons in the car. lol
I dont really know how your car moves, I was assuming you had some sort of waypoints and depending on which button you press, you assigned a different way point for your navmesh.

mNavMeshAgent.destination = UnitScriptName.wayPointsTransform.position;

oh haha, yeah you don’t get them more incompetent than me around here. That makes more sense! Alright thank you :slight_smile: I will dive into it! Have a nice day :slight_smile:

I have only started 2 months ago myself, this is just a suggestion with my limited experience.

Also, Never get intimidated. And always ask questions, it helps others also not just you. So dont feel ashamed to ask questions no matter how “incompetent” you may feel. Trust me I feel it too… but I mean I made like 200 questions in the last 2 months in this forum lol

Thank you for the kind words, I will make sure to push through and ask questions :wink: I really appreciate it :slight_smile:

1 Like