Search Unity

[Help/Hints Wanted] Creating a 3d side scroller camera

Discussion in 'Scripting' started by Jpeppa, Jan 12, 2014.

  1. Jpeppa

    Jpeppa

    Joined:
    Jan 12, 2014
    Posts:
    1
    Hey all,

    So the title is a bit vague, but let me go ahead and elaborate. First off I don't have much experience w/ code. I have used C++ in the past and am learning javascript atm. I know most basics of programming but struggle w/ finding a starting point and logic.

    I have finished a simple tutorial series on Digital Tutors that got me a decent understanding how how to script in Unity and I have created a simple movement script. What I am trying to do now is refine the camera to be more "smooth". I would like the camera to smoothly lead ahead of the character when moving in that direction (Though it doesn't have to be exactly as I described). A similar camera system that I found is in this link for the recently released game "Swapper".

    http://www.youtube.com/watch?v=MHABt6fRo7U

    So enough of my rambling. I was hoping to get some hints or some possible ways that this effect could be done. I would very much like to figure the code out on my own. I will link my movement script below.

    Code (csharp):
    1. var speed : float = 6.0;
    2. var jumpSpeed : float = 6.0;
    3. var gravity : float = 12.0;
    4.  
    5. //This variable is now inheriting the Vector3 info (X,Y,Z) and setting them to 0.
    6. private var moveDirection : Vector3 = Vector3.zero;
    7.  
    8. function MoveAndJump() {
    9.  
    10.     var controller : CharacterController = GetComponent(CharacterController);
    11.        
    12.         if(controller.isGrounded) {
    13.        
    14.             //moveDirection is inheriting Vector3 info.  This now sets the X and Z coords to receive the input set to "Horizontal" and "Vertical"
    15.             moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); //Allows player Input
    16.             moveDirection = transform.TransformDirection(moveDirection);    //How to move
    17.             moveDirection *= speed;     //How fast to move
    18.            
    19.             if(Input.GetButton("Jump")) {
    20.            
    21.                 moveDirection.y = jumpSpeed;
    22.             }
    23.         }
    24.        
    25.         //Apply gravity
    26.         moveDirection.y -= gravity * Time.deltaTime;
    27.        
    28.         //This moves the controller
    29.         controller.Move(moveDirection * Time.deltaTime);
    30. }
    31.  
    32. function Update() {
    33.  
    34.     MoveAndJump();
    35.  
    36. }
    Thank you!
     

    Attached Files: