Search Unity

3rd person demo project [Documenting my progress]

Discussion in 'Scripting' started by tbelgrave, Jul 26, 2007.

  1. tbelgrave

    tbelgrave

    Joined:
    Jul 29, 2006
    Posts:
    321
    Hiya guys, digging my heels in and getting into scripting, I finally have my first question. I would like to create a 3rd person beat em' up demo level and would like to use my Logitech rumble 2 gamepad to play the game. What I would like to have happen at this point is to have the right analog stick rotate the camera around the player character as we've seen many times. Any ideas on how I should tackle this?

    thx!

    ~t
     
  2. Harry1960

    Harry1960

    Joined:
    May 15, 2007
    Posts:
    136
    Open the InputManager (Edit/Project Settings/Input) and add two new axes by increasing the axes count.
    Select for the type property 'Joystick Axis' and '4th axis' under axis.
    Select for the type property 'Joystick Axis' and '3rd axis' under axis.
    If you use 'Mouse X' and 'Mouse Y' as names, you can use the usual code to perform rotations (Input.GetAxis("Horizontal")).
    Fine tune Sensitivity to match your needs.
     
  3. tbelgrave

    tbelgrave

    Joined:
    Jul 29, 2006
    Posts:
    321
    Cheers, I'll give it a try.

    ~t
     
  4. tbelgrave

    tbelgrave

    Joined:
    Jul 29, 2006
    Posts:
    321
    What I'll actually do is, start documenting my progress here so those in my position (artists that can't code!) may benefit from my learning :)

    I don't have any real scope on how this will turn out, but this will be a learning exercise mostly.

    My first goal is to establish a character and define his actions along with the camera. Now please don't help me until I get stuck! I would like to figure out as much on my own first.

    First order of business

    Early Scope


    This will be an action/beat em' up demo level with one character, 2 enemies and a boss character. There will be power-ups along the way (health, additional damage e.t.c) and it'll be in 3rd person.

    Milestones I wish to accomplish first (I'll be using Goober since he's pretty much ready to go, I'll then swap him out)

    *note* I'll be using a logitech rumble pad 2 for my work. I know this alienates peeps without pads, but this is for my personal enjoyment really ;)

    Stage 1:

    1. make character walk
    2. have cam follow character
    3. rotate camera around character with right analog stick
    4. make character collide with objects
    5. make character jump with predefined animation
    6. have character transition from idle>walk>run>jump>land with predefined animations
    7. make cam always follow character (in other words, when the character is facing the screen, have cam gradually rotate back to behind the back view)
    8. have character punch
    9. Assign blob shadow
    10. have character absorb a power up (think of God of War) when they're close enough
    11. have character string a combo when a seq of buttons are pressed in time. If not pressed in time or correct order, have the character just do the single actions.

    That should keep me busy for a month at least heh. Remember don't help just yet. I'll post updates as I accomplish these tasks.

    ~t
     
  5. delirious

    delirious

    Joined:
    Jun 19, 2007
    Posts:
    3
    Hey Lildragn! Thanks for doing this. I took a gander at your site and blog (GREAT STUFF!), and look forward to your progress reports...

    Most of what you want to do is covered in the tutorials or on the forums, so I am sure you'll make quick progress. (at least thats my experience so far...)

    Your project seems character animation intensive (your specialty!?!)

    I see that you use Zbrush 3, (I use Zbrush 2 so far, with C4D).

    As an artist, I am very interested in your pipeline for the character animation (modeling, rigging, animation, texturing, unity), once you figure that out.

    I know that this is a scripting thread :D , but I am most interested in setting up character animations for realtime control through scripts.

    When you are done with Goober (hopefully soon!), I would love to see how you plan to tackle the Character Animation and scripts!

    Good luck!
     
  6. tbelgrave

    tbelgrave

    Joined:
    Jul 29, 2006
    Posts:
    321
    Ok I'm up to number 5. But I'm having limited functionality with the right analog rotation. It rotates about 15° in both directions, but that's it. I'm using the below code in conjunction with the SmoothCamFollow script. Anyone know what I'm doing wrong?

    Code (csharp):
    1.  
    2. // Cam pitch and rotation speed
    3. var camRotation = 50.0;
    4.  
    5.     // Set the axis for camera Pitch and Rotation with right analog stick
    6.     var y = Input.GetAxis("camRotation") * Time.deltaTime * camRotation;
    7.     transform.Rotate(0, y, 0);

    delirious
    Thx man! Great to hear you like m work, appreciated. as to your questions, yup I'm mostly a character type dude, and I love GOW and similar type games, so that's were I'm gonna focus my energy, since I believe I'll go all the way to something complete because of the genre :)

    I do use Zb3 C4D (beta tester for both as a matter of fact) and my pipeline does consist of those, but now it's mostly, Zb3, Max, Photoshop (sometimes Maya as most of my experience is in it).

    As for Goober, I decided to use something even simpler, so I'm not overwhelming myself.
    If anyone here has a gamepad, please feel free to test my efforts so far. It's really basic, so this is more for the help question above. Jump is linked to 2 on the rumble pad (so X if you're a PS2 gamer)

    Back to it :)

    ~t
     

    Attached Files:

  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The main problem is the rotation in the smooth follow script is always going to override the rotation you're setting with the gamepad. I think the best way to fix that is to alter the smooth follow script itself, so you can add rotation from the gamepad directly. Might be a bit tricky. :)

    --Eric
     
  8. tbelgrave

    tbelgrave

    Joined:
    Jul 29, 2006
    Posts:
    321
    Any ideas, suggestions? Should I just use a basic setup for the cam and add this additional code? Because basically the cam needs to follow (translate) while I use the right analog for rotations.

    I actually played a bit of Fantastic Four over the weekend, and I like the way the cam was setup.

    Ok so would this work? I don't have access to Unity until later today.

    Code (csharp):
    1.  
    2. // Define the target that we are following
    3. var target : Transform;
    4.  
    5. // The distance in the x-z plane to the target
    6. var distance = 10.0;
    7.  
    8. // Height we want the camera above the target
    9. var height = 10.0;
    10.  
    11. // Camera rotation speed
    12. var camRotation = 50.0;
    13.  
    14. // How much we want to dampen the camera's motion
    15. var heightDamping = 2.0;
    16.  
    17. // Cameras should always be updated last and LateUpdate allows this
    18. function LateUpdate () {
    19.         // Calculate the current height angles
    20.            wantedHeight = target.position.y + height;
    21.  
    22.            currentHeight = transform.position.y;
    23.  
    24.         // Damp the height
    25.            currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);
    26.        
    27.         // Early out if we don't find a target
    28.            if (!target)
    29.            return;
    30.  
    31.         // Get the forward direction of the target
    32.            forward = target.TransformDirection (Vector3.forward);
    33.        
    34.         // Get the target position
    35.            targetPosition = target.position;
    36.  
    37.         // The camera distance behind target
    38.            transform.position = targetPosition - forward * distance;
    39.  
    40.         // And move the camera a bit up
    41.            target.position.y += height;
    42.  
    43.         // Always look at target
    44.            transform.LookAt (target);
    45.  
    46.         // Set the axis for camera Rotation with right analog stick
    47.            var y = Input.GetAxis("camRotation") * Time.deltaTime * camRotation;
    48.            transform.Rotate(0, y, 0);
    49.  
    50. }
    51.  
    52.  
    ~t
     
  9. tbelgrave

    tbelgrave

    Joined:
    Jul 29, 2006
    Posts:
    321
    Have a question with blob shadow. Is there a way to adjust it so it doesn't affect the top of an object? Shine through in a sense.

    thx

    ~t
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yep, you can put the object on a particular layer, and then tell the blob shadow not to project onto that layer, so it doesn't affect the object at all. (That's just in the inspector; you don't need to script anything.)

    --Eric
     
  11. tbelgrave

    tbelgrave

    Joined:
    Jul 29, 2006
    Posts:
    321
    Excellent thx! Gotta read up on layers!

    ~t