I would like to make a “pet” system, it needs to search for nearby objects and take it to the player, but it is not working.
bool isHit = Physics.SphereCast(transform.position, transform.lossyScale.x/2, transform.position, out hit) ;
if (isHit && estaCarregandoMadeira==false)
{
lastHit = hit.transform.gameObject;
collision = hit.point;
ajudante.SetDestination(hit.transform.position);
}
else
{
ajudante.SetDestination(player.transform.position);
}
brunogrezon:
but it is not working.
“it is not working” is not useful.
How to report your problem productively in the Unity3D forums:
http://plbm.com/?p=220
How to understand compiler and other errors and even fix them yourself:
https://discussions.unity.com/t/824586/8
If you post a code snippet, ALWAYS USE CODE TAGS:
How to use code tags: https://discussions.unity.com/t/481379
Since AI is a VERY open-ended topic, look for some AI that does things like what you want, like foraging or collector agent scripts. This will likely involve some state (“I am available to collect”), some intention (“go collect for me!”), and some navigation, perhaps using Unity pathing.
brunogrezon:
I would like to make a “pet” system, it needs to search for nearby objects and take it to the player, but it is not working.
bool isHit = Physics.SphereCast(transform.position, transform.lossyScale.x/2, transform.position, out hit) ;
if (isHit && estaCarregandoMadeira==false)
{
lastHit = hit.transform.gameObject;
collision = hit.point;
ajudante.SetDestination(hit.transform.position);
}
else
{
ajudante.SetDestination(player.transform.position);
}
You can put if (isHit && !estaCarregandoMadeira)
instead of if (isHit && estaCarregandoMadeira==false)
to make your code more readable.
I believe the problem is that your pet has too low sight to see the object, or you didn’t set up the NavMesh in your scene.