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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by IKilledKenny_2 · Jan 14, 2015 at 04:49 PM · animationjavascriptcollisionrunning

Attack While Running

Hello Unity3D.I have a question about doing animations while running.How can i make it that my character does a certain animation while running and only while running?For example.My characters do certain punches and kicks while standing still.But when i run i want them to do a special punch,such as a superman much or a special kick,such as a back kick.If anyone knows how i can do this.Can you please tell me how?(I can't find any scripts for this for some reason).

 #pragma strict
 var Run:AudioClip;
 var rotationSpeed : float = 10;
 var walkSpeed : float = 7;
 var gravity : float = 50;
 var body : Transform;
 var length: float;
 audio.volume = 0;
 
 private var  yRot: float;
 function Update () {
     var Controller : CharacterController = GetComponent(CharacterController);
     var vertical : Vector3 = transform.TransformDirection(Vector3.forward);
     var horizontal : Vector3 = transform.TransformDirection(Vector3.right);
     var height : Vector3 = transform.TransformDirection(Vector3.up);
 
 
     
     
     if(Input.GetKeyDown("space")){
         animation.Play("Jump");
         Jump();
         
 }
     
     
     
     if(Input.GetAxis("Vertical")||Input.GetAxis("Horizontal")){
         if (!animation.IsPlaying("Jump"))
             if (!animation.IsPlaying("Jump"))
     if(!animation.IsPlaying("Reverse_Crescent"))
     if(!animation.IsPlaying("Crescent"))
     if(!animation.IsPlaying("Spinning_back_kick"))
     if(!animation.IsPlaying("Spinning_back_kick2"))
     if(!animation.IsPlaying("Jump_Spinning_Back_Kick"))
     if(!animation.IsPlaying("Astral_Ball"))
     if(!animation.IsPlaying("Hit1"))
     if(!animation.IsPlaying("Are_You_Ready_"))
     if(!animation.IsPlaying("Kick_Combo"))
     if(!animation.IsPlaying("para_kick"))
     if(!animation.IsPlaying("Aerial_Cartwhell"))
     if(!animation.IsPlaying("Aerial_Cartwhell_Reverse"))
     if(!animation.IsPlaying("Snap_Kick"))
     if(!animation.IsPlaying("Thrust_Kick_2"))
         if(!animation.IsPlaying("Teleport"))
         animation.CrossFade("Run2");
         animation["Run2"].speed = walkSpeed/100;
         
         Controller.Move((vertical * (walkSpeed * Input.GetAxis("Vertical"))) * Time.deltaTime);
         Controller.Move((horizontal * (walkSpeed * Input.GetAxis("Horizontal"))) * Time.deltaTime);
         audio.Play();
 }else{
     if (!animation.IsPlaying("Jump"))
 if(!animation.IsPlaying("Wing_Chun_Punch"))
     if(!animation.IsPlaying("Wing_Chun_Punch_2"))
     if(!animation.IsPlaying("Wing_Chun_Punch_3"))
     if(!animation.IsPlaying("Wing_Chun_Punch_4"))
     if(!animation.IsPlaying("Wing_Chun_Punch_5"))
     if(!animation.IsPlaying("Hit1"))
     if(!animation.IsPlaying("Oh_Hell_To_The_Fuck_Nah_"))
     if(!animation.IsPlaying("Mana_Barrage"))
     if(!animation.IsPlaying("Teleport"))
     if(!animation.IsPlaying("para_kick"))
     if(!animation.IsPlaying("Aerial_Cartwhell"))
     if(!animation.IsPlaying("Aerial_Cartwhell_Reverse"))   
     if(!animation.IsPlaying("Snap_Kick"))
     if(!animation.IsPlaying("Snap_Kick_2"))
     if(!animation.IsPlaying("Thrust_Kick_2"))
     if(!animation.IsPlaying("Hikari_s_Pause"))
     if(!animation.IsPlaying("Frisebee_kick_Part_1"))
     if(!animation.IsPlaying("Mana_Wave_"))
     if(!animation.IsPlaying("Kick"))
     if(!animation.IsPlaying("Kick2"))
     if(!animation.IsPlaying("Chain_Punches"))
     animation.CrossFade("Zen_Fighting_stance_Wing_Chun_");
     
     
         
         Controller.Move((vertical * (walkSpeed * Input.GetAxis("Vertical"))) * Time.deltaTime);
         Controller.Move((horizontal * (walkSpeed * Input.GetAxis("Horizontal"))) * Time.deltaTime);
         audio.Play();
     
 
     }
     
 
     if(Input.GetAxis("Vertical")){
         yRot += 10* Input.GetAxis("vertical");
     }
     
     
 }    
 function LateUpdate(){
   // Rotate the Character to match the direction he/she is going
   if(Input.GetAxis("Vertical") == 0){
     if(Input.GetAxis("Horizontal") > 0){
       body.localEulerAngles.y = 90;//Right sideways running
     }else if(Input.GetAxis("Horizontal") < 0){
       body.localEulerAngles.y = 270;//Left sideways running
 
       
     }
   }else if(Input.GetAxis("Vertical") > 0){
     if(Input.GetAxis("Horizontal") > 0){
       body.localEulerAngles.y = -270;
     }else if(Input.GetAxis("Horizontal") < 0){
       body.localEulerAngles.y = -90;
     }
   }else if(Input.GetAxis("Vertical") < 0){
     if(Input.GetAxis("Horizontal") == 0){
       body.localEulerAngles.y = -180;
     }else if(Input.GetAxis("Horizontal") > 0){
       body.localEulerAngles.y = -180;
     }else if(Input.GetAxis("Horizontal") < 0){
       body.localEulerAngles.y = -180;
     }
   }
 }
 function Jump(){
     gravity = 30;
     yield WaitForSeconds(0.2);
     gravity = -50;
 }
Comment
Add comment · Show 4
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 Owen-Reynolds · Jan 14, 2015 at 04:54 PM 0
Share

Are you talking about how to code for it -- in other words, how do you program "if running and button A, do run smash attack"? Or are you asking about how to play an attack animation combined with a run animation?

avatar image IKilledKenny_2 · Jan 14, 2015 at 06:29 PM 0
Share

Oh im sorry i should have been more specific...What i want is,if im holding the up arrow key and if i press the punch or kick button while holding the up arrow key i do a certain animation.But when im not holding it i do my regular combo animations

avatar image Maurice_B · Jan 14, 2015 at 08:58 PM 0
Share

may i suggest moving to mechanim.

avatar image IKilledKenny_2 · Jan 14, 2015 at 09:03 PM 0
Share

ugh....i tried mecanim...but it always mess up my characters animation and weight paint

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by khos85 · Jan 14, 2015 at 10:44 PM

Have you looked JavaScript's do while loop : http://unity3d.com/learn/tutorials/modules/beginner/scripting/loops

Pseudo code: While running anim is true do jump anim

Might that help get on the right track?

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

29 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

Related Questions

Animation won't start when collision starts 0 Answers

Canceling animation.Play functions after being used 1 Answer

function OnCollosionEnter problems 1 Answer

Ultimate Attack Animation 1 Answer

How do i apply animations in javascript? 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