Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 AshwinTheGammer · Nov 15, 2017 at 11:38 AM · unity 5script.sprintgun-animation

How to create gun sprinting animation by script.

How can I create gun sprinting animation just by script. Please give me script or give me some idea. Any answers to this question is appreciate here.

Comment
Add comment · Show 1
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
avatar image HarshadK · Nov 15, 2017 at 12:14 PM 0
Share

What special requirement needs you to create the animation by script? Because it might be the case that just tweaking some parameters of animation at runtime could yield in the result you want.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Skaster87 · Nov 17, 2017 at 06:54 AM

Hi, I extracted all this from the standard third person controller unity provides, the animationSpeedMultiplier variable will alter how fast your animations cycle.s play.

 using UnityEngine;
 
 using UnityEngine.AI;
 
 public class Character : MonoBehaviour
 
 {
 
     [Header("Animator")]
     [SerializeField]
     RuntimeAnimatorController animatorController;
 
     [SerializeField] AnimatorOverrideController animatorOverrideController;
 
     [SerializeField] Avatar characterAvatar;
 
     [SerializeField] [Range(.1f, 1f)] float animatorForwardCap = 1f;
 
 
     [Header("Nav Mesh Agent")]
 
     [SerializeField]
     float navMeshAgentSteeringSpeed = 1.0f;
 
     [SerializeField] float navMeshAgentStoppingDistance = 1.3f;
 
 
     NavMeshAgent navMeshAgent;
 
     Animator animator;
 
     Rigidbody ridigBody;
 
     public AnimatorOverrideController GetOverrideController()
 
     {
         return animatorOverrideController;
     }
 
 
     void Move(Vector3 movement)
     {
 
         SetForwardAndTurn(movement);
 
         ApplyExtraTurnRotation();
 
         UpdateAnimator();
     }
 
 
 
     void SetForwardAndTurn(Vector3 movement)
 
     {
         // convert the world relative moveInput vector into a local-relative
 
         // turn amount and forward amount required to head in the desired direction
 
         if (movement.magnitude > moveThreshold)
 
         {
             movement.Normalize();
         }
 
 
         var localMove = transform.InverseTransformDirection(movement);
 
         turnAmount = Mathf.Atan2(localMove.x, localMove.z);
 
         forwardAmount = localMove.z;
 
     }
 
 
 
     void UpdateAnimator()
 
     {
         animator.SetFloat("Forward", forwardAmount * animatorForwardCap, 0.1f, Time.deltaTime);
 
         animator.SetFloat("Turn", turnAmount, 0.1f, Time.deltaTime);
 
         animator.speed = animationSpeedMultiplier;
     }
 
 
 
     void ApplyExtraTurnRotation()
     {
 
         // help the character turn faster (this is in addition to root rotation in the animation)
 
         float turnSpeed = Mathf.Lerp(stationaryTurnSpeed, movingTurnSpeed, forwardAmount);
 
         transform.Rotate(0, turnAmount * turnSpeed * Time.deltaTime, 0);
     }
 
 
 
     void OnAnimatorMove()
     {
         // we implement this function to override the default root motion.
         // this allows us to modify the positional speed before it's applied.
         if (Time.deltaTime > 0)
         {
             Vector3 velocity = (animator.deltaPosition * moveSpeedMultiplier) / Time.deltaTime;
 
             // we preserve the existing y part of the current velocity.
             velocity.y = ridigBody.velocity.y;
             ridigBody.velocity = velocity;
         }
     }

But you can import the whole thing by going here -> alt text

But


importcharacters.png (265.7 kB)
Comment
Add comment · Show 2 · Share
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
avatar image AshwinTheGammer · Nov 17, 2017 at 11:33 AM 0
Share

@Skaster87 Thanks for the script but can you tell me how would I implement this code in my gun so that it will sprint. I hope u understand my question.

avatar image Skaster87 AshwinTheGammer · Nov 17, 2017 at 05:40 PM 0
Share

@AshwinTheGammer What code currently controls your movement? Can you provide an example and I may be able to modify it for you.

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

146 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make Animation and Physics work together? 2 Answers

am trying to scaling my ground size in z direction until my player is moving, 2 Answers

Teleporting? 0 Answers

Problem with all my scripts (Not Working Properly) 1 Answer

Playmaker for Unity, Editor won't open! Please HELP!! 1 Answer


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