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 Persona · Dec 06, 2011 at 01:04 AM · fpsarraysshootingraycasting

Shotlock System

I'm trying to make a Shotlock system similar to the one found in Kingdom Hearts BBS, as seen below: This Video Only to be used as a first person perspective.

Now I've figured that I can use raycast to select the enemy by running the target sight over the enemy, and store the enemies in an array, until it hits the preset array limit. Once it does, it uses a "For" loop to fire off the number of shots, which will track the enemy in that array slot.

The problem is that arrays aren't my strong point and can someone show me an example?

Edit:

The script semi works but it can't set the target of the Homing shot and it can't get the same enemy more than once. Any advice?

 function Update () {
 var fwd = transform.TransformDirection (Vector3.forward);
 var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
 var hit : RaycastHit;
 
 if(Input.GetKeyDown("space") && canShotLock){
 isShotLock = true;
 
     }
 
 if(isShotLock){
 
 if(Input.GetKeyDown("x")){
 // On raycast hit, if it's an enemy add it.
 
 if(Physics.Raycast(transform.position, fwd, hit, 100)){
 var hite = hit.transform;
 print(hite);
 if(hite.gameObject.CompareTag("Enemy")){
 SLT[current] = hite;
 print(SLT[current]);    
 current++;
         }
     }
     }
 
 if(Input.GetKeyUp("x")){
 ShotLock();
   }
 
 }
 
 function ShotLock(){
 
 current = 0;
 while (current < SLT.length){
 //current = 0;
 //Instanitate
 print("Firing");
 audio.PlayOneShot(HomingShot);
 var slShot = Instantiate(Homing, transform.position, Quaternion.identity);
 slShot.transform.GetComponent("Projectile").Target = SLT[current].transform;
 slShot.rigidbody.AddForce(transform.forward * 10, ForceMode.Impulse);
 current++;
 yield WaitForSeconds(0.4);    
 }
 canShotLock = false;
 
 }

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by chewychompy · Dec 06, 2011 at 02:03 AM

Using http://unity3d.com/support/documentation/ScriptReference/Array.html

Step 1 Create the array, you have an examples here. Instantiate the array with a GameObject Type. You can store the object for ease of consumption.

You've already got the raycast part and I presume your using a state machine. When your in the "shot locking" state and your cast ray touches an enemy you can use the raycast hit object to get the hit collider object. From the collider you can get the gameObject and you canstore that in the array, see this previous unityanswers answer which is expanded with this forum post here.

A few counters to measure the volume of enemies targeted and your ready to promote your state machine to a "firing" state where you would pull each item out of the array, see first array link, in turn and shoot blobs at them.

I hope this has conceptually bridged some concepts for you. I haven't tried to give you any meaningful code as your situation and understanding is unknown to me. It would be better to develop the code to fit rather than copy and paste some off the internet. Knowledge to understand the answer is of as much use than the answer itself.

Comment
Add comment · Show 2 · 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 Persona · Dec 08, 2011 at 01:52 AM 0
Share

Okay, I tried it and it works partly. Can you help with the last two parts?

avatar image Persona · Dec 10, 2011 at 09:35 AM 0
Share

I tried to put in a while loop that would ray cast the ray if the length wasn't met, but no luck.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How do I make bullet tracers show when I shoot in the air? 1 Answer

Raycast shooting in the middle of the screen 1 Answer

fps shooting in the direction of character main cam 1 Answer

Ultimate FPS not working correctly. 0 Answers

How do I make my bullet tracers show when shooting in the air? 0 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