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
0
Question by ruifernandes01 · May 24, 2012 at 09:03 AM · aiturret

turret AI question

hey everyone! so.. I'm having a problem... I'm making a game of batleships, and i is going very well so far, but now I wanted to make an enemy shoot at me, so i've already make the boat look at me but now i cant make it shoot! this is my script can anyone tell me what is wrong with it?

var bullitprefab: Transform;

shoot();

function shoot(){

 var bullit = Instantiate(bullitprefab, transform.Find("SpanwPoint").transform.position, Quaternion.Identity);
 
 
 
 bullit.Rigidbody.AddForce(transform.right * 1000);
 
 }

this should be this be enought, right?

Comment
Add comment · Show 1
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 asafsitner · May 24, 2012 at 09:24 AM 0
Share

It should, but what is calling the Shoot function?

3 Replies

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

Answer by Hybris · May 24, 2012 at 04:31 PM

Well nothing is really wrong with it but the variable bullitprefab has to be rigidbody. Let me give you an example on how I would use this, and explain some stuff:

 var bulletprefab : Rigidbody;//has to be rigidbody to fire, and made it "bullet" instead of "bullit"
 var spawn : Transform;

 function Update(){

 if(Vector3.Distance(transform.position, Transform.Find("Player")) < 10){   
 //if the distance between player and enemy is beneath 10 do the following:

 shoot();
 }
 }

 function shoot(){

  var bullet = Instantiate(bulletprefab, spawn.position, transform.rotation);



 bullet.rigidbody.AddForce(transform.right * 1000); // had to be rigidbody notRigidbody

 }

Comment
Add comment · Show 9 · 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 ruifernandes01 · Jun 18, 2012 at 07:59 PM 0
Share

tnx a lot $$anonymous$$, but now i have this error when i'm compiling it:

expecting ( found 'shoot', when you crate a new function.. any idea of wht it might be?

avatar image Hybris · Jun 23, 2012 at 07:36 PM 0
Share

Edited my answer, and by some reason my nickname won't show.... well that's my problem.

avatar image ruifernandes01 · Jun 23, 2012 at 08:33 PM 0
Share

i'm still with the same problem, in line twelve..

avatar image Hybris · Jun 24, 2012 at 07:40 AM 0
Share

oh srry, for some reason it didn't update, it should work now. add at the end of update function an {

remove the last } of the shoot function, srry my mistake it's hard to throw in code

avatar image ruifernandes01 · Jun 24, 2012 at 01:05 PM 0
Share

no problem! :) now there is an problem on :

if(Vector3.Distance(transform.position, transform.Find("Player")) < 10){

Show more comments
avatar image
0

Answer by ruifernandes01 · May 24, 2012 at 02:59 PM

I'm kind of a newbie in scripting... i've created my function, one called Shoot.right?

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
avatar image
0

Answer by ruifernandes01 · May 24, 2012 at 09:07 PM

hey, thanks for your availability! I now have some errors like:

alt text

can you "inlightme" one more time? plz


Unity erros.png (124.5 kB)
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 Hybris · May 25, 2012 at 06:31 PM 0
Share

last } too much, srry will update my answer right away!...stupid me......thats like very stupid of me...cant believe it..

BTW plz make a comment ins$$anonymous$$d of an answer

oh and unity acts weird if you still have the error of var not expected do this:

var bullet : Rigidbody; bullet = Instantiate(bulletprefab, spawn.position, transform.rotation);

It's just the long way around, sometimes unity does this I don't know why

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

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

trouble with my lookAt script 0 Answers

Trouble with turret script 1 Answer

AI using Javascript 1 Answer

Enemies Moving Through Terrain Help 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