Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by tdog3323 · Aug 31, 2011 at 12:45 PM · errorturrettornado-twins

tornado twins worm game tutorial turret not firing

im trying to follow the youtube tutorial, but i cannot make the turret to fire, the script is exactly the same, and i do have a spawn point, script is:

 var LookAtTarget:Transform;
 var damp = 6.0;
 var bullitPrefab:Transform;
     
 

 

 function Update () 
 {
     if(LookAtTarget)
     {
         var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position);
             
         transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);
             
         Shoot();
     }
 }
     
 function Shoot()
 {
     var bullit = Instantiate(bullitPrefab, transform.find("SpawnPoint").transform.position ,
                                 Quaternion.identity);
                                 
     bullit.rigidbody.AddForce(transform.forward * 1000);
                             
 
 }
 
Comment
Add comment · Show 6
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 SisterKy · Aug 31, 2011 at 04:04 PM 1
Share

please hit edit -> select all code -> hit the 1010101 button to format your code.

I was about to blame 'bullit' for the difficulties (since it's supposed to be 'bullet'... at least in the english language I learned at school) but it seems to be consistently (ab)used, so it's probably not the problem... o.O

can you start the game? any error-messages in the console? or is it just not doing what it should? describe a little more what's going on.

avatar image SisterKy · Sep 01, 2011 at 12:27 PM 0
Share

Ok, try this. add inside the if(LookAtTarget)-statement:

 print("I have a Target");

and add inside the Shoot-function at the beginning:

 print("I'm trying to shoot");

and add inside the Shoot-function at the end:

 print(bullit);

this way you can tell where the problem is happening.

avatar image Borgo · Sep 01, 2011 at 12:50 PM 0
Share

There is any error message?
Do you have a "SpawnPoint" object in the scene?
A hint: try to Understand the tutorial, don't just make exactly as said. Try to understand each peace of code.

avatar image SisterKy · Sep 01, 2011 at 01:02 PM 0
Share

@Borgo hrm... his formatting and answer-ins$$anonymous$$d-of-comment makes it less accessible, but he already answered both questions. He gets no error-messages and has a spawnpoint. What makes you doubt he's trying to understand the tutorial?

avatar image Borgo · Sep 01, 2011 at 01:20 PM 1
Share

@Sister$$anonymous$$y: Sorry, I did not see
And my comment about "understand" is because he is writing exactly the video as required, including spelling errors.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by kgoswami · Sep 08, 2011 at 07:01 AM

Change "find" to "Find" with a capital "F" here is the line of code. Also make sure your spelling of the "spawnPoint" is correct. Check the turret for spawnPoint object name.

 var bullit= Instantiate(bullitPrefab,transform.Find("spawnPoint").transform.position,Quaternion.identity);    //create bullet


Also after doing this code and adding it to your turret, click the turret object in your heirarchy and drag your worm object into the LookAtTarget Prefab box on the inspector window and the fireball prefab into the bullitprefab box of your inspector window. Also one more thing is that do not add your worm prefab as your lookattarget, add the worm object from your scene heirarchy. But I can see that u are not having problems with the looking part. also you can make thw turret actually move closer to your character uptil a certain distance.

Here is the code.

 var ahead=transform.TransformDirection(Vector3(0,0,1));            //Go  ahead  direction 
         var distance=Vector3.Distance(LookAtTarget.position,transform.position); //calculate distance between turret and player
         if(distance>enemyStopDist)                                        //keep distance from player
         {
             turretController.SimpleMove(ahead*turretMovSpeed);
         }
 //Here, enemyStopDist is a var that is  the  distance at which the turret will stop moving closer to your worm

Hope this helps.

Comment
Add comment · Show 1 · 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 tdog3323 · Sep 08, 2011 at 08:14 AM 0
Share

thankyou, it worked :)

avatar image
0

Answer by kgoswami · Sep 08, 2011 at 07:19 AM

A better way is to not use Find. Just as you have var bullitPrefab:Transform and dragged your fireball into it you can use var spawnPointPrefab:Transform. After doing this follow these steps. Make your spawnpoint object into a transform by dragging it from the Heirarchy to project window. Drag your spawnPoint object(not prefab, but the one in your heirarchy window) from the turret object (not prefab) into the turret>inspector>turretControl>spawnPointPrefab box.

This way the unity run time environment does not have to search for every object to find your spawnPoint.

Comment
Add comment · 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

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

6 People are following this question.

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

Related Questions

I need a turret script 4 Answers

Please help with Turret rate of fire 1 Answer

TornadoTwins Tutorial Problem 4 Answers

Scripting error comes up when I press play 1 Answer

Turret Script Problem 2 Answers


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