• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by CotA · Nov 30, 2011 at 03:09 AM · javascriptai

Javascript A* pathfinding

Hi everyone,

So, for an RPG game, I have been assigned the task of creating AI. What I would like to do is use the A* pathfinding asset form arongranberg.com, but am having some troubles. He uses C#, and I want to use Javascript. Now, I know the project enables JS support, and I have enabled the JS support, but my problem is, how do I use this enabled support?

Here is an example of my problem. I started the Getting Started tutorial from the documentation page, and was doing great up until the creating of code. I tried to recreate the code from c# to js, but was not sure how, and ended up failing.

Does anyone have any experience using the A* pathfinding asset from the Unity Store but used JS instead of C#. Help on this subject would be much appreciated.

Code given in guide (in C#)

 using UnityEngine;
 using System.Collections;
 //Note this line, if it is left out, the script won't know that the class 'Path' exists and it will throw compiler errors
 //This line should always be present at the top of scripts which use pathfinding
 using Pathfinding;
 
 public class AstarAI : MonoBehaviour {
     public Vector3 targetPosition;
 
     public void Start () {
         Seeker seeker = GetComponent<Seeker>();
         
         //Start a new path to the targetPosition, return the result to the MyCompleteFunction
         seeker.StartPath (transform.position,targetPosition, MyCompleteFunction);
     }
     
     public void MyCompleteFunction (Path p) {
         Debug.Log ("Yey, we got a path back. Did it have an error? "+p.error);
     }
 }

My code (in JS. Not even sure if syntax is right!)

 using Pathfinding;
 
 
 
     public var targetposition : Vector3;
 
 
 
     function Start () {
 
         var seeker : Seeker = GetComponent<Seeker>();
 
         
 
         //Start a new path to the targetPosition, return the result to the MyCompleteFunction
 
         seeker.StartPath (transform.position,targetPosition, MyCompleteFunction);
 
     }
 
     
 
     function MyCompleteFunction (Path p) {
 
         Debug.Log ("Yey, we got a path back. Did it have an error? "+p.error);
 
     }
 
 } 
Comment
Add comment · Show 8
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image milali · Nov 30, 2011 at 03:22 AM 0
Share

I guess my 1st question is why do you want to use java? Are you more familiary with it?

C# is a more widely used language for unity these days from what I can tell...

avatar image CotA · Nov 30, 2011 at 03:31 AM 0
Share

well, I build web apps, and use javscript there.

And as a senior in high school, I am part of the AP comp sci class, and the curriculum is in java.

Plus, the group I am part of uses javascript.

So javascript it is.

avatar image DaveA · Nov 30, 2011 at 04:22 AM 0
Share

If there's a chance you can hold off until 3.5, it has wonderful AI built in.

avatar image CotA · Nov 30, 2011 at 04:28 AM 0
Share

When does that come out?

avatar image Eric5h5 · Nov 30, 2011 at 04:33 AM 0
Share

Folks, Java and Javascript are completely different things. Also, web Javascript is almost nothing like "Javascript" in Unity, which should really be called Unityscript.

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

AI isn't looping (Javascript) 1 Answer

My Object only moves when the variable ready is true. Problem is that ready is only ever true while update is running. So to move the object the variable always has to be true. How can I make it move if the variable ready is false. 1 Answer

ERROR : QUACK is not a generic definition. What now? 1 Answer

Simple follow script issue 1 Answer

iTween Help Please MoveTo not working 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges