- Home /
Multiplayer Animation
ok i know this is a commonly asked question but i have a specific case and do not understand why this isnt working i have this attached to each character
var animator : Animation;
var walk : String = "Walk_Forward";
var strafe : String = "strafe";
var run : String = "run";
var idle : String = "idle";
var jump : String;
var walkAnimationSpeed : float = 2;
var strafeAnimationSpeed : float = 2;
var runAnimationSpeed : float = 2;
var runThreshold : float;
@HideInInspector
var runWalkRatio : float;
@HideInInspector
var action : boolean = true;
@HideInInspector
var lastPos : Vector3;
@HideInInspector
var deltaPos : Vector3;
var speedMagnitude : float;
var weightFwd : float;
function Start () {
}
function FixedUpdate () {
action = false;
deltaPos = transform.position - lastPos;
speedMagnitude = deltaPos.magnitude;
weightFwd = Mathf.Abs(Vector3.Dot(transform.forward.normalized, deltaPos.normalized));
var walkSpeed : float = deltaPos.magnitude * weightFwd;
var strafeSpeed : float = deltaPos.magnitude * (1 - weightFwd);
if(weightFwd < .1){
weightFwd = 0;
animator.Stop(walk);
}
if(weightFwd > .9){
weightFwd = 1;
animator.Stop(strafe);
}
if(gameObject.GetComponent(PlayerMove).grounded){
if(weightFwd > .2 && deltaPos.magnitude > .015){
Forward(walkSpeed, weightFwd);
action = true;
}
if(weightFwd < .8 && deltaPos.magnitude > .015){
Strafe(strafeSpeed, 1 - weightFwd);
action = true;
}
}
if(!action){
// animator.Stop();
animator.CrossFade(idle, .1);
}
lastPos = transform.position;
}
function Forward (speed : float, weight : float) {
animator[walk].speed = speed * walkAnimationSpeed;
animator[run].speed = speed * runAnimationSpeed;
if(deltaPos.magnitude > runThreshold)
animator.Blend(run,runWalkRatio);
else
animator.Blend(walk, weight - runWalkRatio);
}
function Strafe (speed : float, weight : float) {
animator[strafe].speed = speed * strafeAnimationSpeed;
animator.Blend(strafe, weight, .1);
}
so in theory each animation calculations and playing should happen locally (which is better than RPC as far as i understand) but except for player character the only animation that plays is the dle animation, so i kno that the animations are playing but why is it that the other animations will not play? is it because of how the transform is observed and updated, and more importantly how can i fix it?
Answer by Bunny83 · May 04, 2012 at 02:41 AM
I never used the Blend function but from what i can read from the scripting reference it just blends the animation weight, nothing more. It doesn't start (enable) the animation. Usually you would use either Animation.Play or Animation.CrossFade.
Alternatively you can of course set all parameters manually. Take a look at the AnimationState class which represents a concrete animation. However it's usually better to use one of the two functions above unless you need full control of all active animations.
i tried to do this but it changed nothing it what i really need to know is why it is not playing since it should be calculated locally. also if wat u say is the case about Blend() not starting the animation why does it work for rhe user player?