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 Daniel Olvera · Mar 09, 2013 at 07:46 PM · cameratimebulletfollowinstantiated

Camera following Bullet

Hi, im making a FPS game, but when i shoot i want the camera starts following the object, like bullet time in matrix, i've tried a lot of "answers" with similar topics at this site, but i cant get it to work, here is the code where i create the bullet:

 var bullet:GameObject;
 var sound1: AudioClip;
 
 
 function Start () {
 
 
 }
 
 function Update () {
 
     if(Input.GetButtonDown("Fire1")){
         audio.PlayOneShot(sound1);
         var bulletInstance:GameObject = Instantiate(bullet,transform.position,Quaternion.identity);
     
         
         
         Physics.IgnoreCollision(transform.root.collider , bulletInstance.collider);
         
         bulletInstance.rigidbody.AddForce(
         Camera.mainCamera.transform.TransformDirection(Vector3(0,0,100))
         ,ForceMode.Impulse);
         
         
         
         
         
     }
 
 }


thanks!

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
Best Answer

Answer by Griffo · Mar 09, 2013 at 08:01 PM

The way I do it is add another camera to the scene then child the bullet model you have to it then save the camera as the bullet prefab ready to Instantiate as your bulletInstance.

Then put 2 new variables at the top of your script -

 var Camera2 : Camera;
 private var Camera1 : Camera;

Drop your bullet prefab into the Camera2 slot in the Inspector, then in the Start function add -

 Camera1 = Camera.main;

Then when you fire your bullet add -

 Camera1.enabled = false;
 Camera2.enabled = true;

Then add a script to your bullet prefab with the reverse -

 Camera1.enabled = true;
 Camera2.enabled = false;

Triggered on collision of the bullet.

Hope this helps.

Comment
Add comment · Show 5 · 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 Daniel Olvera · Mar 09, 2013 at 08:59 PM 0
Share

Hi Griffo, thanks for the answer, i did what you said and it worked fine, however i still have some issues:

*The main camera its a child from the FPS character, so how do i activate it again from the bullet script?

*The camera is with the bullet all the time, im wondering if there's something i can do for the camera to be behind the bullet.

Thank you very much!

avatar image Daniel Olvera · Mar 09, 2013 at 09:25 PM 0
Share

Oh, i manage to switch cameras, so thats no longer a problem, i still sarching about how to put the camera behind the bullet, thanks

avatar image Griffo · Mar 10, 2013 at 08:02 AM 0
Share

To put the camera behind the bullet just drop the prefab into the scene then if you did as I said you should have the camera with the bullet as its child, just click on the bullet and move it slightly forward until its where you want it in view of the camera, then delete the original prefab and drop this one into the prefab folder as the new one, then the next time you fire you should see the bullet just in front of the camera.

If my original answer was correct please mark as answered, the tick, thank you.

avatar image Daniel Olvera · Mar 10, 2013 at 07:44 PM 0
Share

Thank you so much for your time and your answers, now it works perfectly!

avatar image dev01 · Jan 31, 2017 at 04:55 PM 0
Share

How do you quite the triggered on Collision thing?

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

12 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

Related Questions

Super Monkey Ball type Camera? 2 Answers

How to make your character move? 7 Answers

Fire bullet to mouse position in 3d space 1 Answer

Follow an object with camera -1 Answers

How do I let a camera follow on one axis? 3 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