Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 RudyPython · Dec 16, 2014 at 07:53 PM · third-personthird-person-shooter

Third Person Shooter help?

Hi friends,

I am building this Third Person Shooter game, I already have the basic animations for the character such as Walk, Run, etc... I am having trouble making the character draw a weapon. Also, I want the left hand of the character to be in the gun. I know the Inverse Kinematics (IK) is used for this, but I don't really know IK.

Can anyone help me with this or reference me to a tutorial? Thanks in advance.

Here is a sample of my code:

using UnityEngine; using System.Collections;

[RequireComponent(typeof(Animator))] [RequireComponent(typeof(CapsuleCollider))] [RequireComponent(typeof(Rigidbody))] public class CharacterControl : MonoBehaviour {

     public float animSpeed = 1.5f;                
     
     public float walkSpeed = 4.0f;
     public float runSpeed = 8.0f;
     private Animator anim;                            
     private AnimatorStateInfo currentBaseState;            
     private CapsuleCollider col;                    
     private bool run = false;
     private bool IsGrounded = true;
     private bool strafeR = false;
     private bool strafeL = false;
     static int idleState = Animator.StringToHash ("Base Layer.Idle");
     static int walkState = Animator.StringToHash ("Base Layer.Walk");                
     static int strafeLeft = Animator.StringToHash ("Base Layer.StrafeLeft");
     static int strafeRight = Animator.StringToHash ("Base Layer.StrafeRight");
     static int runState = Animator.StringToHash ("Base Layer.Run");
     static int jumpState = Animator.StringToHash ("Base Layer.Jump");

     void Start ()
     {
             // initialising reference variables
             anim = GetComponent<Animator> ();
             col = GetComponent<CapsuleCollider> ();
             if (anim.layerCount == 2)
                     anim.SetLayerWeight (1, 1);
             run = false;
             strafeR = false;
             strafeL = false;
     }

     void FixedUpdate ()
     {
             float h = Input.GetAxis ("Horizontal");                
             float v = Input.GetAxis ("Vertical");                
             anim.SetFloat ("Speed", v);                             
             anim.SetFloat ("Direction", h);                                 
             anim.speed = animSpeed;                                
             anim.SetLookAtWeight (lookWeight);                    
             currentBaseState = anim.GetCurrentAnimatorStateInfo (0);    

             CheckRun ();
             StrafeWalk ();
     }

     void OnCollisionEnter (Collision collider)
     {
             IsGrounded = true;
     }

     public void CheckRun ()
     {
             if (Input.GetKey (KeyCode.LeftShift))
                     run = true;
             else
                     run = false;
     
     
             if (run == true) {
         
                     anim.SetBool ("Run", true);
             }
             if (run == false) {
         
                     anim.SetBool ("Run", false);
             }
     }

     public void StrafeWalk ()
     {
             if (Input.GetKey (KeyCode.Q)) 
                     strafeL = true;
              else 
                     strafeL = false;
             
             
             if (strafeL == true) {
                     anim.SetBool ("StrafeL", true);
             }
             if (strafeL == false) {
                     anim.SetBool ("StrafeL", false);
             }

             if (Input.GetKey (KeyCode.E)) 
                     strafeR = true;
             else 
                     strafeR = false;
             
             if (strafeR == true) {
                     anim.SetBool ("StrafeR", true);
             }
             if (strafeR == false) {
                     anim.SetBool ("StrafeR", false);
             }
     }

}

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

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

What is the best way to do third person melee combat? 1 Answer

3rd person character flying 1 Answer

A Third person Animated character 2 Answers

change first person controller collider to cube 1 Answer

Problems implementing TPP camera that doesn't go through walls 2 Answers


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