Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Demo Scene - Snake - Navmesh
#4
(20-08-2024, 10:47 PM)devmert Wrote: My English is not very good, I guess I explained it wrong. I know how to use Navmesh, what I meant was

We can control the snake in snake demo scene with keyboard. You have a snake controller script.

I want to learn this. How can I make changes to the script so that this snake goes where I click in the scene. Where should I start? It's a very general question, but I could use some advice. Thanks

Hi,

Assuming you already have the position in space you want the snake to move towards, the key is realizing what do the existing input controls allow the snake to do:

- You can point the head of the snake using WASD.
- You can make the snake move in the direction that the head is pointing by pressing J.

So all you have to do is point the head (which is a regular transform) towards the target position using vector math instead of keyboard input, then make the snake advance until the head is sufficiently close to it. If you have trouble with the math, I'd suggest starting there. Some resources:

https://docs.unity3d.com/Manual/VectorCookbook.html
https://learn.unity.com/tutorial/vector-maths

kind regards,
Reply


Messages In This Thread
Demo Scene - Snake - Navmesh - by devmert - 20-08-2024, 08:27 PM
RE: Demo Scene - Snake - Navmesh - by josemendez - 20-08-2024, 09:12 PM
RE: Demo Scene - Snake - Navmesh - by devmert - 20-08-2024, 10:47 PM
RE: Demo Scene - Snake - Navmesh - by josemendez - 21-08-2024, 07:44 AM