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 SheheryarAamir · Feb 04, 2013 at 07:09 AM · camerabulletcamera-lookfollow player

How To Make Camera Follow Bullet?

Hi, I'm new in Unity game development. I am design a third person shooter game. What I want is when player fires a bullet camera should follow that bullet to its target. What I did so far is:

camera.forward = shot.transform.forward;

Vector3 newTargetPosition = shot.transform.position + (Vector3.up*2) + (Vector3.forward*5);

camera.position = newTargetPosition;

camera.LookAt(shot.transform.position);

Problem facing: When player turn back and fires bullet camera follow bullet from the front instead of follow that bullet from the back.

Please suggestion what/where I'm doing wrong?

Thanks in advance.

Comment
Add comment · Show 5
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 Sanky · Feb 04, 2013 at 07:38 AM 0
Share

try this wiil help you

var target : Transform;

// Rotate the camera every frame so it keeps looking at the target function Update() { transform.LookAt(target); }

avatar image SheheryarAamir · Feb 04, 2013 at 07:48 AM 0
Share

All of the mentioned code in my last post is in update function.

$$anonymous$$y Problem is camera position is not always at the back of the bullet. It depends on the player/gun position. if player turn left camera follow the bullet but shows left side of the bullet.

avatar image SheheryarAamir · Feb 04, 2013 at 07:58 AM 0
Share

I think following line has the problem: shot.transform.position + (Vector3.up*2) + (Vector3.forward*5); I multiply Vector3Up with 2 and Vector3.forward with 5. I did this because I want camera to follow bullet from a little distance. but still struggling how to solve this :[

avatar image Sanky · Feb 04, 2013 at 10:20 AM 0
Share

Had u tried smooth follow camera for this this camera also working like object follow

avatar image SheheryarAamir · Feb 04, 2013 at 10:50 AM 0
Share

No, can you please share?

2 Replies

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

Answer by Ruthra · Feb 04, 2013 at 11:39 AM

Maybe you should go simplier and temporary make the camera transform a child of your bullet GameObject, then back to your character controller when bullet hit target.

This way it wouldn't be affected anymore by your controller position or rotation.

Unity Documentation on transform parent

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 SheheryarAamir · Feb 04, 2013 at 11:58 AM 0
Share

Thanks. Everything is working fine now. :)

avatar image
0

Answer by anilgautam · Feb 04, 2013 at 11:06 AM

take the position of bullet and change the position of camera according to bullet position

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 SheheryarAamir · Feb 04, 2013 at 11:29 AM 0
Share

camera.transform.position = bullet.transform.position I did this and everything is working fine. the only problem I am facing is: camera is exactly at the same position of the bullet and because of this bullet is not visible in the scene. what I want is; camera should follow bullet with a little bit of distance and height. To achieve this I add Vector3 UP and forward in current position of the bullet and assign it to the camera:

camera.transform.position = bullet.transform.position +(Vector3.up*2) + (Vector3.forward*5);

and by doing this camera follow the bullet fine only in one direction.

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

Camera follow a sphere which look at another object on the ground 0 Answers

Player camera targeting/locking another object 0 Answers

Enable the OrbitCam script how can I make it will continue from the current camera view and position ? 0 Answers

Camera gets stuck when cursor is locked 0 Answers

How to make the second camera rotate automatically? 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