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 SM · Mar 25, 2011 at 04:50 PM · animationshootingthird-person

repeating a shooting animation

I'm trying to put together a simple set of animations on a third person character. At the moment I have an idle, a walk, and a shoot and reload. The shoot and reload are blended on top of the other animations, so the character can shoot/ reload and walk/ idle.

What I would like to know - is there a way to get the shoot animation to keep on playing with the mouse button pressed down? At the moment I have to release and repress to get the shoot animation to play again.

If I change GetButtonDown to GetButton this can repeat but this doesn't work with the mixing and crossfade. If I change the animation to play rather than crossfade then the mixing looks awful on the character (I'm using the first spine joint as the mixer root) but the animation repeats until the mouse button is released.

Any way to have the animation blending/ mixing nicely and being able to hold the mouse button down to carry on firing?

(Eventally I will have a "bring to firing position/ one shot fire" animation and then a "repeat firing" animation, but that's a way off yet(.

Here is my current script:

/// Adds a mixing transform using a Transform variable public var shoulder : Transform; animation["shoot"].AddMixingTransform(shoulder); animation["reload"].AddMixingTransform(shoulder);

private var leanLeft : AnimationState; private var leanRight : AnimationState;

function Start () {

// Set all animations to loop animation.wrapMode = WrapMode.Loop; // except shooting animation["shoot"].wrapMode = WrapMode.Once; animation["reload"].wrapMode = WrapMode.Once;

// Put idle and walk into lower layers (The default layer is always 0) // This will do two things // - Since shoot and idle/walk are in different layers they will not affect // each other's playback when calling CrossFade. // - Since shoot is in a higher layer, the animation will replace idle/walk // animations when faded in. animation["shoot"].layer = 1; animation["reload"].layer = 2;

// Stop animations that are already playing //(In case user forgot to disable play automatically) animation.Stop();

 leanLeft = animation["leanLeft"];
 leanRight = animation["leanRight"];

// Put the leaning animation in a separate layer // So that other calls to CrossFade won't affect it. leanLeft.layer = 10; leanRight.layer = 10;

// Set the lean animation to be additive leanLeft.blendMode = AnimationBlendMode.Additive; leanRight.blendMode = AnimationBlendMode.Additive;

// Set the lean animation ClampForever // With ClampForever animations will not stop // automatically when reaching the end of the clip leanLeft.wrapMode = WrapMode.ClampForever; leanRight.wrapMode = WrapMode.ClampForever;

// Enable the animation and fade it in completely // We don't use animation.Play here because we manually adjust the time // in the Update function. // Instead we just enable the animation and set it to full weight leanRight.enabled = true; leanLeft.enabled = true; leanRight.weight = 1.0; leanLeft.weight = 1.0;

// For testing just play "walk" animation and loop it //animation["walk"].wrapMode = WrapMode.Loop; //animation.Play("walk");

}

function Update () { // Play either the run or idle animation if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1) { animation.CrossFade("walk"); // Play animation backwards when running backwards animation["walk"].speed = Mathf.Sign(Input.GetAxis("Vertical")); } else animation.CrossFade("idle");

// Shoot if (Input.GetButtonDown ("Fire1")) animation.CrossFade ("shoot");
if (Input.GetButtonDown ("reload")) animation.CrossFade("reload");

 // Every frame just set the normalized time
 // based on how much lean we want to apply

var lean = Input.GetAxis("Horizontal"); // normalizedTime is 0 at the first frame and 1 at the last frame in the clip leanLeft.normalizedTime = -lean; leanRight.normalizedTime = lean;

}

Thanks

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by kyle83great · Jun 21, 2012 at 10:40 PM

im only a 13 year old teen...but i do know how to do loop

animation["shoot"].wrapMode = WrapMode.Once;

rather then that then use

animation["shoot"].wrapMode = WrapMode.Loop;

Comment
Add comment · 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

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

1 Person is following this question.

avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Gun clipping through walls in third person shooter 1 Answer

Wait for reload to finish? 1 Answer

Bullet shooting animation 1 Answer

Created Animations only play half within Animator 0 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