- Home /
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;
}
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?
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
ugh....i tried mecanim...but it always mess up my characters animation and weight paint
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?
Your answer
Follow this Question
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