Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Scripting vs Animation - FPS

Discussion in 'Scripting' started by IntelligentDesign, Jun 21, 2014.

  1. IntelligentDesign

    IntelligentDesign

    Joined:
    Jun 13, 2014
    Posts:
    51
    Hey all,

    So I'm trying to teach myself Unity by building an FPS (if anyone's interested in talking about that, the basic idea is Tony Hawk + FPS + Game Show). I've run into a number of design decisions already, and I could use a few opinions before I move on. I should note that I'm building everything from the ground up: no FPS controller or prefab character, I really want to learn how everything works. Also I've been working from ETeeski's youtube tutorial series, which for any other noobs is a really great way to learn as he takes time to explain the code before writing it in front of you. That said

    1) Is making the player a RigidBody capsule a good idea, or is there a better way to create a player GameObject? This method seems to have some advantages, but I've had a few problems (Unity's gravity seems to leave everything feeling very floaty, if you're up against a wall the friction can cause you to stick to it allowing you to "hover", etc).

    2) Is using camera.ViewportPointToRay a good means of casting the bullet rays? The way I handle bullets right now is to always generate them from the muzzle, but the when I fire from the hip everything is slightly off-center (specifically to the right and below the middle of the screen). Is there any downside to faking it by casting from the screen's center?

    3) Does anyone know a good way to implement muzzle climb? The tutorial I'm watching does a good job of having side to side bullet spread and vertical spread, as well as having the gun move back along its Z-axis to simulate recoil, but I'm not sure how to get the muzzle to climb with each round fired like I know it should.

    4) If I'm including gun models and arm models (as well as possibly a torso model with legs) what should be handled in-script and what should be handled in animation? For example, when walking I know head bobbing should be handled in a script, but what about gun bobbing? Is that an idle animation or would I actually write a script to move the arm models? For recoil, is it an animation I play or do I use a script to control the rig points (ie on fire move elbow back 2 units, or something like that)?

    If anyone has answers to these questions, or some sagely advice they'd like to pass along I'd really appreciate it. Thanks in advance!
     
  2. static_cast

    static_cast

    Joined:
    Aug 25, 2013
    Posts:
    25
    This would be some VERY useful information for beginners... if anybody would reply to it.

    I'm very interested in seeing what one would say about #4.

    As for the other points, here's my view:
    1) I've noticed that if you add a player material with no friction, this problem disappears. [of course you'll have slower times for deceleration]

    2) Typically I just raycast from Camera.main.transform.eulerAngles, as it's not a function so you don't have to worry about any sort of slowdowns. [while slowdowns would be minimal, it's best to write efficient code anyway]

    3) In order to do muzzle climb, you could have an incrementing variable that you would add to the bullet angle to make it go upwards. You could also move the camera up incrementally.

    4) Dunno, hoping for answers. ;)
     
  3. Crayz

    Crayz

    Joined:
    Mar 17, 2014
    Posts:
    192
    Did some Googlin' on this the other day and found if you create a new Physics Material, set the friction to 0, friction amount to Minimum, then apply the material to your player's collider he won't stick to walls anymore. You can also disable Unity's default gravity (Rigidbody.useGravity = false) and apply it manually in FixedUpdate.

    #4

    I found this headbob method to be pretty effective and easy to set up, rather then working with sine wave formulas and whatnot. The same could probably be done for arms & weapons. Because recoil affects a player's aim and view angles it might be better to keep it to script that way you can keep it all in sync.
     
  4. static_cast

    static_cast

    Joined:
    Aug 25, 2013
    Posts:
    25

    #4 Head bobbing should actually be done through script as using an animation is would be inefficient. [at least from what I've heard]

    Take a look at this http://www.reddit.com/r/Unity3D/comments/2bj934/an_approach_to_recoil_and_general_weapon_movement/. This shows a good way of doing #4.