If you have any questions about implementing your NavMesh, here is the perfect place for them…
I’m super proud of myself. For the first time since I started coding was I able to do the challenge and feel confident about it. I feel like for the first time I actually understand how to code. I looked it up in the unity docs and figured it out on my own. I have always struggled with the challenges and felt like I was getting nowhere. All the persistence has paid off now I just need to keep pushing that boulder up the mountain and keep learning. My skills need a lot of work but i’m so happy when I write a piece of code expecting a result and I actually achieve that result.
So awesome! Its a really good feeling once you push through that tough phase and things start to stick.
Thank you Rick!
I am having no luck at getting my player to move at all. Hoping it is something really obvious that i have missed:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class Mover : MonoBehaviour
{
[SerializeField] Transform target;
// Update is called once per frame
void Update()
{
GetComponent<NavMeshAgent>().destination = target.position;
}
}
Nav mesh baked, Player named player, Target name target.
Nav mesh agent and Mover script attached to player.
not sure what else i could be missing?
never mind i fixed it.
just needed to add the target into the serialised field:
don’t think this was covered during the lecture, did i miss something?
yes you missed this it was covered in video number 9 at time frame 7:42
https://www.udemy.com/unityrpg/learn/lecture/13631942#overview
Handy way to mark something as navigation static: just implement that setting in its prefab editor!
What error do you get?
Make sure you drag the target gameobject from Heirarchy to the Player’s inspector window
hello rick sir,
i started designing project boost training from 3 days.i have no idea about coding.
by your great lectures i nearly design our rocket boost 2nd level.with this speed i have great confidence that im gona finish all the tutors in 45 days.
upto (23. Level Loading & Scene Management) works like a charm…
but (24. Invoke() As A Coroutine Warm-up) after implementing this scripts in this 24 th chapter, in my game if i completes the level or if i am dead the game freezes there.
sir, i m using unity 2018.3.3f1 version.visual studio 2017 version & windows 10. plz suggest me fix for this problem sir…mny mny thnks in adv for your time n help rick sir…
this my Script sir…
using UnityEngine;
using UnityEngine.SceneManagement;
public class Rocket : MonoBehaviour
{
[SerializeField] float rcsThrust=200f;
[SerializeField] float mainThrust =200f;
Rigidbody rigidBody;
AudioSource audioSource;
enum State { Alive, Dying, Transcending }
State state = State.Alive;
// Start is called before the first frame update
void Start()
{
rigidBody = GetComponent<Rigidbody>();
audioSource = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update()
{
if (state == State.Alive)
{
Thrust();
Rotate();
}
}
void OnCollisionEnter(Collision collision)
{ if (state != State.Alive)
{
return; //ignore collisions when dead..
}
switch (collision.gameObject.tag)
{
case "Friendly":
//do nothing
Debug.Log("ok");// TODO remove..
break;
case "Finish":
state = State.Transcending;
Invoke("LoadNextLevel", 1f) ;//parameterize time..
break;
default:
state = State.Dying;
Invoke("LoadFirstLevel", 1f);//parametrise time..
break;
}
}
private static void LoadNextLevel()
{
SceneManager.LoadScene(1);// to do allow More then 2 levels
}
private static void LoadFirstLevel()
{
SceneManager.LoadScene(0);
}
private void Thrust()
{
if (Input.GetKey(KeyCode.Space))
{
rigidBody.AddRelativeForce(Vector3.up * mainThrust);
if (!audioSource.isPlaying)
{
audioSource.Play();
}
}
else
{
audioSource.Stop();
}
}
void Rotate()
{
rigidBody.freezeRotation = true; //take manual controll of rotation..
float rcsThrust = 200f;
float rotationthisframe = rcsThrust * Time.deltaTime;
if (Input.GetKey(KeyCode.A))
{
transform.Rotate(Vector3.forward * rotationthisframe);
}
else if (Input.GetKey(KeyCode.D))
{
transform.Rotate(-Vector3.forward * rotationthisframe);
}
rigidBody.freezeRotation = false; //resumes phisics controll of rotation..
}
}
In my case the Player was not moving to the target. Everything was correct but I have pressed “clear” after pressing “bake” button in Navigation tab. I went back to Navigation tab and pressed “bake” again and everything was OK after that.
Had the same problem. Thought the bake was only meant to show you what the path would be, not that it was needed to make the player move.
If you are using NavMesh to move anything in your game then it will need to have the nav mesh correctly baked in order for it to move.
Just a suggestion, maybe Sam could talk about or implement dynamic navMesh baking in part 2, there are a ton of cool things that can be done if you set up said navMesh.
the feeling of utter defeat when you knew exactly what code to right but didnt know navmesh needed a name space. i guess thats my fault for not knowing what it meant by name space when i read the error but now i do lol
Hello!
Why are you calling GetComponent in the Update method?
I stored the NavMeshAgent component in a variable in Start() then just set the destination of the veriable in Update()
Challenge Result!!
when i click on Bake, nothing is happening in my scene
Only in bottom right corner
Exporting tiles is filled
Hmmm… that means something is going wrong with Unity itself in the baking process, it’s getting hung up. Have you tried restarting Unity?