protected override void OnAdded(Group parent) { var scene = parent.FindRoot <Scene>(); camera = scene.GetDrawingContext().Camera; var model = parent.Find <Nine.Graphics.Model>(); // Blend between 3 animation channels var idle = new BoneAnimationController(model.Source.GetAnimation("Idle")); var carry = new BoneAnimationController(model.Source.GetAnimation("Carry")); var run = new BoneAnimationController(model.Source.GetAnimation("Run")); var blended = new BoneAnimation(model.Skeleton); blended.Controllers.Add(idle); blended.Controllers.Add(run); blended.Controllers.Add(carry); lookAtController = new LookAtController(model.Skeleton, model.AbsoluteTransform, model.Skeleton.GetBone("Bip01_Head")); lookAtController.Up = Vector3.UnitX; lookAtController.Forward = -Vector3.UnitZ; lookAtController.HorizontalRotation = new Range <float>(-MathHelper.PiOver2, MathHelper.PiOver2); lookAtController.VerticalRotation = new Range <float>(-MathHelper.PiOver2, MathHelper.PiOver2); blended.Controllers.Add(lookAtController); // Give the look at controller a huge blend weight so it will dominate the other controllers. // All the weights will be normalized during blending. blended.Controllers[lookAtController].BlendWeight = 10; blended.KeyController = run; blended.IsSychronized = true; model.Animations.Play(blended); }
// Start is called before the first frame update void Start() { animator = GetComponentInChildren <Animator>(); input = GetComponent <PlayerInput>(); rb = GetComponent <Rigidbody>(); lookAtController = transform.root.GetComponentInChildren <LookAtController>(); horizontalHash = Animator.StringToHash("horizontal"); verticalHash = Animator.StringToHash("vertical"); isMovingHash = Animator.StringToHash("isMoving"); // Spawn weapon weapon = Instantiate(weapon); weapon.transform.parent = weaponAttach.transform; weapon.transform.localPosition = Vector3.zero; weapon.transform.localRotation = Quaternion.Euler(90, 0, 0); Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; }
public void Awake() { if(canLookAt) lookAt = body.GetComponent<LookAtController>(); if(lookAt == null) canLookAt = false; if(breatheClip != null) { body.animation[breatheClip.name].blendMode = AnimationBlendMode.Additive; body.animation[breatheClip.name].layer = 1; } else Debug.LogWarning(gameObject.name + " starting with no breatheClip!!"); //if(postures.Count > 0 && !animInit) //InitAnimations(); // whoever gets here first can build these: if (maleClips == null){ maleClips = new Dictionary<string,AnimationClip>(); Object[] mObjs = Resources.LoadAll("Animations/Male"); // this seems pretty lame, but this is how we apparently have to instantiate these for (int i=0; i<mObjs.Length; i++){ Instantiate(mObjs[i]); maleClips.Add (mObjs[i].name, mObjs[i] as AnimationClip); } } if (femaleClips == null){ femaleClips = new Dictionary<string,AnimationClip>(); Object[] mObjs = Resources.LoadAll("Animations/Female"); // this seems pretty lame, but this is how we apparently have to instantiate these for (int i=0; i<mObjs.Length; i++){ Instantiate(mObjs[i]); femaleClips.Add (mObjs[i].name, mObjs[i] as AnimationClip); } } if (animationScriptObject == null){ Object SOB = Resources.Load("Animations/AnimationScripts"); GameObject go = Instantiate (SOB) as GameObject; if (go != null){ animationScriptObject = go.GetComponent<ScriptedObject>(); } } }
// Start is called before the first frame update private void Start() { _fik = GetComponent <FullBodyBipedIK>(); _headIk = GetComponent <LookAtIK>(); _lookAt = GetComponent <LookAtController>(); }