Discussions
Sign In
Forum rules
- please read before posting.
How do i get the X and Y coordinates of the player and a NPC within the AC environment?
Antonis
May 2014
edited May 2014
in
Technical Q&A
Would like to get the point that the user clicked for the player to go to in a scene and the current point that an NPC is standing within AC environment. Any help?
Comments
ChrisIceBox
May 2014
Provided you have a Paths component attached to the Player prefab, this will get you the end of the Player's path:
if
(GameObject.FindWithTag (Tags.player) && GameObject.FindWithTag (Tags.player).GetComponent <Paths>())
{
Paths p = GameObject.FindWithTag (Tags.player).GetComponent <Paths>();
if (p.nodes.Count > 0)
{
Vector3 playerTarget = GetComponent <Paths>().nodes [GetComponent <Paths>().nodes.Count - 1];
}
}
And to get the position of an NPC (set to the public variable myNPC):
Vector3 npcPosition = myNPC.transform.position;
Sign In
or
Register
to comment.
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Register
Quick Links
Categories
Recent Discussions
Categories
12K
All Categories
63
Official news
1.5K
Engine development
10.1K
Technical Q&A
319
Games showcase
149
Extending the editor
222
Adventure talk
Welcome to the official forum for Adventure Creator.
Forum rules
Main website
Store page
Community wiki
Community Discord
Powered by Vanilla
Comments
if (GameObject.FindWithTag (Tags.player) && GameObject.FindWithTag (Tags.player).GetComponent <Paths>())
{
Paths p = GameObject.FindWithTag (Tags.player).GetComponent <Paths>();
if (p.nodes.Count > 0)
{
Vector3 playerTarget = GetComponent <Paths>().nodes [GetComponent <Paths>().nodes.Count - 1];
}
}
And to get the position of an NPC (set to the public variable myNPC):
Vector3 npcPosition = myNPC.transform.position;