Kaelen
Kaelen
CC#
Created by Kaelen on 5/30/2023 in #help
❔ Nav Mesh Agent doesnt avoid obstacles
Here is my pathfind class :
public class pathFinding : MonoBehaviour
{

private NavMeshAgent navMeshAgent;
// Start is called before the first frame update
void Start()
{
navMeshAgent = GetComponent<NavMeshAgent>();
}

public void MoveTo(Vector3 dir){
navMeshAgent.SetDestination(dir);
}

}
public class pathFinding : MonoBehaviour
{

private NavMeshAgent navMeshAgent;
// Start is called before the first frame update
void Start()
{
navMeshAgent = GetComponent<NavMeshAgent>();
}

public void MoveTo(Vector3 dir){
navMeshAgent.SetDestination(dir);
}

}
9 replies
CC#
Created by Kaelen on 5/30/2023 in #help
❔ Nav Mesh Agent doesnt avoid obstacles
Then I set the direction of my agent to this point :
private void newDir(zombieStateManager zombie){
if (RandomPointOnNavMesh.RandomPoint(zombie.transform.position, range, out point))
{
Debug.DrawRay(point, Vector3.up, Color.blue, 1.0f);
}
Debug.Log(point);
zombie.pathFind.MoveTo(point);
Debug.Log("Changement de position :" + point);
}
private void newDir(zombieStateManager zombie){
if (RandomPointOnNavMesh.RandomPoint(zombie.transform.position, range, out point))
{
Debug.DrawRay(point, Vector3.up, Color.blue, 1.0f);
}
Debug.Log(point);
zombie.pathFind.MoveTo(point);
Debug.Log("Changement de position :" + point);
}
9 replies
CC#
Created by Kaelen on 5/30/2023 in #help
❔ Nav Mesh Agent doesnt avoid obstacles
I search a random point on the nav mesh :
public class RandomPointOnNavMesh : MonoBehaviour
{

public static bool RandomPoint(Vector3 center, float range, out Vector3 result)
{
for (int i = 0; i < 30; i++)
{
Vector3 randomPoint = center + Random.insideUnitSphere * range;
NavMeshHit hit;
if (NavMesh.SamplePosition(randomPoint, out hit, 1.0f, NavMesh.AllAreas))
{
result = hit.position;
return true;
}
}
result = Vector3.zero;
return false;
}

}
public class RandomPointOnNavMesh : MonoBehaviour
{

public static bool RandomPoint(Vector3 center, float range, out Vector3 result)
{
for (int i = 0; i < 30; i++)
{
Vector3 randomPoint = center + Random.insideUnitSphere * range;
NavMeshHit hit;
if (NavMesh.SamplePosition(randomPoint, out hit, 1.0f, NavMesh.AllAreas))
{
result = hit.position;
return true;
}
}
result = Vector3.zero;
return false;
}

}
9 replies
CC#
Created by Kaelen on 4/18/2023 in #help
❔ Animation never stop c#
This is because my currentMovement is never set to 0 at y and x even if I release the button. How can I solve it ?
5 replies
CC#
Created by Kaelen on 1/1/2023 in #help
❔ My Raycast seems to be upside down
I change the layer index to the layer mask
32 replies
CC#
Created by Kaelen on 1/1/2023 in #help
❔ My Raycast seems to be upside down
its a old code
32 replies
CC#
Created by Kaelen on 1/1/2023 in #help
❔ My Raycast seems to be upside down
private RaycastHit2D hitInfo;

private GameObject grabbedObject;
private int layerIndex;

void Awake() {
layerMask = LayerMask.GetMask("Objects");
hitInfo = Physics2D.Raycast(transform.position, -transform.right, 2f, layerMask);
}
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{

if (hitInfo.collider) // never set to true
{
Debug.DrawRay(transform.position, -transform.right * 2f, Color.green);
Debug.Log(hitInfo.collider.name); // renvoie mon prefab, or c'est le poin d'entrée


} else {
Debug.DrawRay(transform.position, transform.right * 2f, Color.red);
}
}
}
private RaycastHit2D hitInfo;

private GameObject grabbedObject;
private int layerIndex;

void Awake() {
layerMask = LayerMask.GetMask("Objects");
hitInfo = Physics2D.Raycast(transform.position, -transform.right, 2f, layerMask);
}
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{

if (hitInfo.collider) // never set to true
{
Debug.DrawRay(transform.position, -transform.right * 2f, Color.green);
Debug.Log(hitInfo.collider.name); // renvoie mon prefab, or c'est le poin d'entrée


} else {
Debug.DrawRay(transform.position, transform.right * 2f, Color.red);
}
}
}
32 replies
CC#
Created by Kaelen on 1/1/2023 in #help
❔ My Raycast seems to be upside down
so the hit.collider always stays to null
32 replies
CC#
Created by Kaelen on 1/1/2023 in #help
❔ My Raycast seems to be upside down
even when I hit the layer in question
32 replies
CC#
Created by Kaelen on 1/1/2023 in #help
❔ My Raycast seems to be upside down
the color of the layer is red
32 replies
CC#
Created by Kaelen on 1/1/2023 in #help
❔ My Raycast seems to be upside down
sorry Im french
32 replies
CC#
Created by Kaelen on 1/1/2023 in #help
❔ My Raycast seems to be upside down
this one set the drawray to red, but when I hit the layer that I want to target, it stay to red
32 replies
CC#
Created by Kaelen on 1/1/2023 in #help
❔ My Raycast seems to be upside down
this one doesnt change anything
32 replies
CC#
Created by Kaelen on 1/1/2023 in #help
❔ My Raycast seems to be upside down
but I precised that only some layers should be triggered
32 replies
CC#
Created by Kaelen on 1/1/2023 in #help
❔ My Raycast seems to be upside down
private RaycastHit2D hitInfo;

private GameObject grabbedObject;
private int layerIndex;

void Awake() {
layerIndex = LayerMask.NameToLayer("Objects");
hitInfo = Physics2D.Raycast(transform.position, -transform.right, 2f, layerIndex);
}
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{

if (hitInfo.collider)
{
Debug.DrawRay(transform.position, -transform.right * 2f, Color.green);
Debug.Log(hitInfo.collider.name);
// //Prendre l'item
// if (Keyboard.current.spaceKey.wasPressedThisFrame && grabbedObject == null)
// {
// grabbedObject = hitInfoFridge.collider.gameObject;
// grabbedObject.GetComponent<Rigidbody2D>().isKinematic = true;
// grabbedObject.transform.position = grabPoint.position;
// grabbedObject.transform.SetParent(transform);
// }

// //Rel�cher l'objet
// else if (Keyboard.current.spaceKey.wasPressedThisFrame)
// {
// grabbedObject.GetComponent<Rigidbody2D>().isKinematic = false;
// grabbedObject.transform.SetParent(null);
// // grabbedObject = null;
// // }

} else {
Debug.DrawRay(transform.position, transform.right * 2f, Color.red);
}
}
}
private RaycastHit2D hitInfo;

private GameObject grabbedObject;
private int layerIndex;

void Awake() {
layerIndex = LayerMask.NameToLayer("Objects");
hitInfo = Physics2D.Raycast(transform.position, -transform.right, 2f, layerIndex);
}
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{

if (hitInfo.collider)
{
Debug.DrawRay(transform.position, -transform.right * 2f, Color.green);
Debug.Log(hitInfo.collider.name);
// //Prendre l'item
// if (Keyboard.current.spaceKey.wasPressedThisFrame && grabbedObject == null)
// {
// grabbedObject = hitInfoFridge.collider.gameObject;
// grabbedObject.GetComponent<Rigidbody2D>().isKinematic = true;
// grabbedObject.transform.position = grabPoint.position;
// grabbedObject.transform.SetParent(transform);
// }

// //Rel�cher l'objet
// else if (Keyboard.current.spaceKey.wasPressedThisFrame)
// {
// grabbedObject.GetComponent<Rigidbody2D>().isKinematic = false;
// grabbedObject.transform.SetParent(null);
// // grabbedObject = null;
// // }

} else {
Debug.DrawRay(transform.position, transform.right * 2f, Color.red);
}
}
}
32 replies
CC#
Created by Kaelen on 1/1/2023 in #help
❔ My Raycast seems to be upside down
And how is it possible since that the object is the entry point ?
32 replies
CC#
Created by Kaelen on 1/1/2023 in #help
❔ My Raycast seems to be upside down
How could I fix that?
32 replies
CC#
Created by Kaelen on 12/31/2022 in #help
✅ [RESOLVED]It seems that my variables is destroyed after the Awake()
@Korbah
4 replies
CC#
Created by Kaelen on 12/31/2022 in #help
✅ [RESOLVED]It seems that my variables is destroyed after the Awake()
Should I use a coroutine ?
4 replies