• 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 Karsnen_2 · Dec 07, 2011 at 04:58 AM · camera2djavascriptfovfieldofview

Camera movement in a 2D? (like angry birds)

Hello,

The project is a projectile motion using a cannon. It is a

  1. Side scroller ( meant that the view is 2D).

  2. The canon has to be placed on the left corner and fire in a Projectile Fashion.

Expectation :

My main aim is to view the entire scene when enemy is spawned randomly (once per time). Mainly I want the user to have the vision as of where the enemy cube (target) is placed. I would also want a transition to be smooth. Say, could take half a second. Moreover as because the cube is spawned everytime it is instantiated, sometimes the cube might be very near the cannon. If that is the case - I would be happy if the cube retreats back to the original position (something like in the screenshot "game_view"). I was just looking into the documentation and I was thinking whether that would be possible either by alternating the z axis of the camera of it's FOV. But I thought someone who had prior experience in this type of scenario could guide me well. The entire game moves on X-Y Plane. Hence at all cases Z co-ordinates is '0'.

ScreenShots:

  1. Game View alt text The game view which is the normal position of the camera. Whenever the enemy is within this view I would prefer the camera to remain in this position. I mean I would like to camera to have this position as the least position and move from here to cover the enemy (which spawns only) onto the positive far end of X co-ordinates.

  2. Scene View alt text That cube at the far end is the enemy. It is the target for the enemy.

  3. FOV change alt text This is one of the options I had.

  4. Transform Z co-ordinates alt text Another option I have.

  5. Angry Birds : alt text I would like to have something like this. I think the camera lets the view the entire scene by just zooming out.

Code :

I have ideas in bits and pieces. But for the transition I could use Unity's in build TIME function.

 Enemy's Position :

The enemy's position is set to random on one co-ordinate only. I set the position through,

 function e_spawn()
 {
     pos = projscript.spawn();
     var position: Vector3 = Vector3(pos, 1, 0);
     Instantiate(ene_pos, position, Quaternion.identity);
 }

The turret's position is always fixed and It is set to Vector3(-0.02,1.05,0)

Request :

I humbly request is could someone help me out. I think I am stuck. If I am helped with some code, I would highly appreciate. I hope I did not feed in too much on information and at the same time provide all the required information.

Thank you very much

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 hatzalex · Dec 08, 2011 at 12:53 PM

Hi karsnen,

If I understand correctly all you want to do is zoom in and out. Then I think that just changing the FOV of the camera should be sufficient. As for making it smooth all you need to do is set a startFOV and an endFOV, and let the FOV change over time. Something like this:

 var mnCamera : Camera;
 var startFOV = 60;
 var endFOV = 30;
 var changeIncrement = 0.3;
 
 if (mnCamera.fieldOfView >= endFOV)
         {
             mnCamera.fieldOfView -= changeIncrement;        
         }
  if(mnCamera.fieldOfView <= startFOV)
         {
             mnCamera.fieldOfView += changeIncrement;
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 Karsnen_2 · Dec 08, 2011 at 10:59 PM 0
Share

Thanks bud. I will implement it. I guess that is something similar to what I expect.

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

Find out if GameObject is in Field of View 2 Answers

2d camera help! 0 Answers

Negative results when converting HFOV to VFOV? 1 Answer

Automatically adjust cameras FOV to maintain a perfect 360 coverage with multiple cameras 0 Answers

Is there a way to set the horizontal field of view of a camera? 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