Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 sanghai · Sep 09, 2011 at 05:05 AM · cameracamera-lookcamera.maincamera-scrolling

Need help for camera view like Air Strike 3d game ?

Hello Everyone,I am beginner for unity and trying to make game of aeroplane like Air Strike 3d ........ I need help in camera section. I want to move my cam just like in that game where it is following the Airplane along x axis as well as when air plane goes to left it scrolls on left for say 100 m and same goes with right

I dont think its smooth follow because it is not following airplane i guess ... Please please help me with the soultion

I tried making a new empty game object and drag both camera and airplane in it ...and then tried smooth follow script but its not the way i wanted..

I am sory if i could not explain the problem properly here is the link of the Air Strike 3d

this is the link http://www.youtube.com/watch?v=zHkARvzsrMU

check the video after 4.42 minutes to avoid the information screen and all..

See in that screen scrolls little bit left ...right and i dont think its smooth follow if it is then please provide me the solution....if possible i will be very thankful...

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

2 Replies

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

Answer by Nonakesh · Sep 09, 2011 at 09:47 AM

I don't think the camera is following the player along the x (I don't think its the x-axis, but you know what I mean^^), but the player is following the camera! (he is limited how far he can go forward and backward depending on the position of the camera)

Ok... now the scrolling.... I think the camera starts scrolling as soon as the player is at certain distance to the player.

 if(Math.Abs(Camera.main.transform.position - transform.position) > scrollDistance){
     //start moving camera
 }
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 sanghai · Sep 09, 2011 at 11:19 AM

Thanks dude you made my day ... ( by the way i understood what you meant ^-^) .............Sorry

By the way I have done this and it is working but my when my airplane goes to left it goes smoothly but when i try to come back again to the normal position or to d right

Airplane gets jerk or shock .... ( understood what i mean ....:) )

what should i do about that jerk .... ?

var scrollDistance:float =100.0;

private var endtarget=100.0; working

function Update(){

         /*transform.position.y=currentHeight;
         transform.position.z = target.position.z - distance;*/
         
         if(Mathf.Abs(Camera.main.transform.position.x - transform.position.x) > scrollDistance)
         {
         //start moving camera
             Camera.main.transform.position.x= transform.position.x + endtarget;

         }
 
 

}

Comment
Add comment · Show 6 · 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 Nonakesh · Sep 11, 2011 at 11:41 AM 0
Share

O$$anonymous$$! Sry for the late answer.... but you really should have used the comment button, ins$$anonymous$$d of answer!

This should work:

var scrollDistance:float =100.0;

var scrollSpeed = 1;

 function Update(){

     transform.position.x += Input.GetAxis("Horizontal");    

     /*transform.position.y=currentHeight;
     transform.position.z = target.position.z - distance;*/

    if($$anonymous$$athf.Abs(Camera.main.transform.position.x - transform.position.x) > scrollDistance)

    {

         Camera.main.transform.position.x += scrollSpeed * $$anonymous$$athf.Sign(Camera.main.transform.position.x - transform.position.x);

    }

}

btw... don't forget to press "Correct answer" ;D

avatar image sanghai · Sep 14, 2011 at 03:52 PM 0
Share

THAN$$anonymous$$ YOU VERY $$anonymous$$UCH ............. O ya i sorry for not using comment button ...but now I did !!!

avatar image Nonakesh · Sep 15, 2011 at 12:49 PM 0
Share

yeah... you made it REALLY the right way... you pressed correct answer on you own answer, not on $$anonymous$$e.. :/

avatar image sanghai · Sep 16, 2011 at 06:46 AM 0
Share

Hello ..... need help again ... I run your script its working properly but now its constantly following the plane in center....If you will see the Air Strike 3D game its behaving like ... If plane is in center and after some distance say 20 meters to the left then camera also scrolls to the left for the same distance around and then it comes to the distance where camera stops to the extent left but not the plane .... Here its not following the plane in center ... whereas camera moves first ...

I have made this script but dont know its not working ... I have just done for the left for right now Please check

public float scrollDistance = 100.0f; public int scrollSpeed = 1; private float x_Scroll_Left; private float x_Scroll_Right; public float smoothTime = 0.3F; private float yVelocity = 0.0F; private float newPosition;

// Use this for initialization void Start () { $$anonymous$$oveAirPlane someScript; someScript = GetComponent<$$anonymous$$oveAirPlane>();

x_Scroll_Left= (someScript._init_x - someScript._horizontal_extent)/2; x_Scroll_Right = someScript._init_x + someScript._horizontal_extent;

}

// Update is called once per frame void Update () {

 //Debug.Log("co$$anonymous$$g ");
 if (transform.position.x >= x_Scroll_Left)
 {
     //float newPosition = $$anonymous$$athf.SmoothDamp(Camera.main.transform.position.x,(transform.position.x + 100), ref yVelocity, smoothTime);
 // Camera.main.transform.position.x += scrollSpeed * $$anonymous$$athf.Sign(Camera.main.transform.position.x - transform.position.x);
 // Camera.main.transform.position.x += scrollSpeed * $$anonymous$$athf.Sign(Camera.main.transform.position.x - transform.position.x);
    //float newPosition = Camera.main.transform.position.x  smoothTime;
     newPosition += scrollSpeed * $$anonymous$$athf.Sign(Camera.main.transform.position.x - transform.position.x);
     Camera.main.transform.position = new Vector3(newPosition, Camera.main.transform.position.y, Camera.main.transform.position.z);
    //Camera.main.transform.position = new Vector3(scrollSpeed * transform.position.x,Camera.main.transform.position.y,Camera.main.transform.position.z);
 } 
avatar image sanghai · Sep 16, 2011 at 06:46 AM 0
Share

After playing for so much time now I might guess that camera is not following the airplane because Air Plane is moving freely even after camera scrolls without camera being moved .... please help ...thanks in advance

Show more comments

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 can I make a smooth camera transition over time with java script? 1 Answer

Is there any way to keep game object withing the limit of Camera FOV 3 Answers

RTS type of camera 1 Answer

Camera/can't turn on X 1 Answer

[Unity3D] Game Scene and Making Scene is different 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