Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
-1
Question by Steff120 · Nov 14, 2013 at 07:39 PM · javascripterrortoken

Unexpected token: targetPos

I get an error where my TOKEN is wrong, and I would really like too know what a token is :P. (Noob Here) So if you could help me that would be nice ^^

function (CalculateAimPosition targetPos = Vector3)

{

    var aimPoint = Vector3(targetPos.x + aimError, targetPos.y + aimError, targetPos.z + aimError);

    desiredRotation = Quaternion.LookRotation(aimPoint);

};

Comment
Add comment · Show 17
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 donutkeith · Nov 14, 2013 at 08:14 PM 0
Share

Is targetPos a Transform?

avatar image Steff120 · Nov 14, 2013 at 08:24 PM 0
Share

What do you mean?

avatar image donutkeith · Nov 14, 2013 at 09:19 PM 0
Share

is targetPos a Transform type. When you declared targetPos what type did you give it. var targetPos : Transform;

avatar image Steff120 · Nov 15, 2013 at 05:44 PM 0
Share

Well, I added that, but it still dosen't work. Got any other ide? :S

avatar image KiraSensei · Nov 15, 2013 at 06:12 PM 0
Share

Could you be more specific when you say "it does not work" ? Does it compile ? Do you have an error on runtime ?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by KiraSensei · Nov 15, 2013 at 04:13 PM

Try :

 function CalculateAimPosition (targetPos:Transform)
 {
     var aimPoint = Vector3(targetPos.x + aimError, targetPos.y + aimError, targetPos.z + aimError);
  
     desiredRotation = Quaternion.LookRotation(aimPoint);
 }


EDIT : here is the entire script :

 var myProjectile : GameObject;
 var reloadTime : float = 1f;
 var turnSpeed : float = 5f;
 var firePauseTime : float = .25f;
 var muzzleEffect : GameObject;
 var errorAmount : float = 0.01f;
 var myTarget : Transform;
 var turretBall: Transform;
 var muzzlePositions : Transform;
 var targetPos : Transform;
 
 private var nextFireTime : float;
 private var nextMoveTime : float;
 private var desiredRotation : Quaternion;
 private var aimError : float;
 
 function Start () {
 
 }
 
 function Update () {
 
     if(myTarget)
     {
         if(Time.time >= nextMoveTime)
         {
             CalculateAimPosition(myTarget.position);
             turretBall.rotation = Quaternion.Lerp(turretBall.rotation.desiredRotation.time.deltaTime * turnSpeed);
         }
         if(Time.time >= nextFireTime)
         {
             FireProjectile();
         }
     }
 }
 
 function OnTriggerEnter (other : Collider) {
     if (other.gameObject.tag == "Enemy")
     {
         nextFireTime = Time.time + (reloadTime * 0.5);
         myTarget = other.gameObject.transform;
     }
 }
 
 function OnTriggerExit (other : Collider){
     if(other.gameObject.transform == myTarget)
     {
         myTarget = null;
     }
 }
 
 function CalculateAimPosition (targetPos : Vector3) {
     var aimPoint = Vector3(targetPos.x + aimError, targetPos.y + aimError, targetPos.z + aimError);
     desiredRotation = Quaternion.LookRotation(aimPoint);
 }
 
 function CalculateAimError {
     aimError = Random.Range(-errorAmount, errorAmount);
 }
 
 function FireProjectile {
     audio.Play();
     nextFireTime = Time.time + reloadTime;
     nextMoveTime = Time.time + firePauseTime;
     CalculateAimError();
 
     for(theMuzzlePos in muzzlePositions)
     {
         Instantiate(myProjectile, theMuzzlePos.position, theMuzzlePos.rotation);
         Instantiate(muzzleEffect, theMuzzlePos.position, theMuzzlePos.rotation);
     }
 }
Comment
Add comment · Show 6 · Share
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 drod7425 · Nov 15, 2013 at 06:24 PM 0
Share

Almost, $$anonymous$$iraSensei. Remove the ';' at the very end and that is the correct answer. If OP had been more informative with the errors, we would have had it by now.

avatar image KiraSensei · Nov 15, 2013 at 06:28 PM 0
Share

oh, yes of course :) Stupid copy/paste :)

avatar image KiraSensei · Nov 15, 2013 at 09:06 PM 0
Share

Now if you have other errors, please tell exactly what they are and at what line.

avatar image Steff120 · Nov 16, 2013 at 03:47 PM 0
Share

50,9 unexpected token: myTarget

Life is hard time to time xdd :P

avatar image KiraSensei · Nov 16, 2013 at 03:52 PM 0
Share

Why did you declare myTarget as a Transform[] ? It should be a Transform.

I reedited the code with others corrections

In a line you put :

 myTarget : null;

This implies that you really don't know how to code. So you should stop trying like this and learn.

Show more comments

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.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

expecting EOF, found 'else'. 2 Answers

unity not working help 2 Answers

Could not preload global game manager #0 0 Answers

Hi I get an error code when i'm using my Javascript and I can't understand how to fix it... :( 1 Answer

Camera annoying error helps error 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