x


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...

more ▼

asked Sep 09 '11 at 05:05 AM

sanghai gravatar image

sanghai
61 13 13 16

(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

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
}
more ▼

answered Sep 09 '11 at 09:47 AM

Nonakesh gravatar image

Nonakesh
115 7 9 11

(comments are locked)
10|3000 characters needed characters left

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;

       }

}

more ▼

answered Sep 09 '11 at 11:19 AM

sanghai gravatar image

sanghai
61 13 13 16

OK! Sry for the late answer.... but you really should have used the comment button, instead 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(Mathf.Abs(Camera.main.transform.position.x - transform.position.x) > scrollDistance)

   {

        Camera.main.transform.position.x += scrollSpeed * Mathf.Sign(Camera.main.transform.position.x - transform.position.x);

   }

}

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

Sep 11 '11 at 11:41 AM Nonakesh

THANK YOU VERY MUCH ............. O ya i sorry for not using comment button ...but now I did !!!

Sep 14 '11 at 03:52 PM sanghai

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

Sep 15 '11 at 12:49 PM Nonakesh

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 () { MoveAirPlane someScript; someScript = GetComponent();

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("coming ");
if (transform.position.x >= x_Scroll_Left)
{
    //float newPosition = Mathf.SmoothDamp(Camera.main.transform.position.x,(transform.position.x + 100), ref yVelocity, smoothTime);
// Camera.main.transform.position.x += scrollSpeed * Mathf.Sign(Camera.main.transform.position.x - transform.position.x);
// Camera.main.transform.position.x += scrollSpeed * Mathf.Sign(Camera.main.transform.position.x - transform.position.x);
   //float newPosition = Camera.main.transform.position.x  smoothTime;
    newPosition += scrollSpeed * Mathf.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);
} 
Sep 16 '11 at 06:46 AM sanghai

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

Sep 16 '11 at 06:46 AM sanghai
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2988
x65
x18
x8

asked: Sep 09 '11 at 05:05 AM

Seen: 932 times

Last Updated: Sep 16 '11 at 06:48 AM