VR Development Framework
v 1.0.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
AVR_SimpleAvatar.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 #if UNITY_EDITOR
5 using UnityEditor;
6 #endif
7 
8 namespace AVR.Avatar
9 {
10  /// <summary>
11  /// Avatar component that doesn't require controllers.
12  /// </summary>
13  [RequireComponent(typeof(Animator))]
14  [AVR.Core.Attributes.DocumentationUrl("class_a_v_r_1_1_avatar_1_1_a_v_r___simple_avatar.html")]
15  public class AVR_SimpleAvatar : AVR.Core.AVR_Component
16  {
17  private Animator animator;
18  private Vector3 lastPos = Vector3.zero;
19 
20  /// <summary>
21  /// Animation parameter that corresponds to the speed the player is moving at.
22  /// </summary>
23  public string speedAnimationParameter = "Speed";
24 
25  protected override void Start()
26  {
27  base.Start();
28  animator = GetComponent<Animator>();
29 
30  animator.logWarnings = false; //TODO: This disables warning-spam if parameters (like "Speed") dont exist. Perhaps this should be optional based on a setting.
31 
32  lastPos = playerRig.FeetInWorldSpace;
33  }
34 
35  void Update()
36  {
37  if(!this.enabled) Debug.Log("????????????");
38 
39  animator.SetFloat(speedAnimationParameter, playerRig.AvgMotion.magnitude);
40 
41  if(playerRig.AvgMotion.magnitude > 0.3f) {
42  transform.forward = Vector3.Lerp(transform.forward, playerRig.AvgMotion, 0.05f);
43  }
44  else
45  {
46  transform.forward = Vector3.Lerp(transform.forward, playerRig.XZPlaneFacingDirection, 0.05f);
47  }
48 
49  if(Vector3.Distance(lastPos, playerRig.FeetInWorldSpace) > 0.1f) {
50  lastPos = Vector3.Lerp(lastPos, playerRig.FeetInWorldSpace, 0.1f);
51  }
52 
53  transform.position = lastPos;
54  }
55  }
56 }
Sets the documentation html file inside of Packages/com.avr.core/Documentation/html of a given class...
Avatar component that doesn't require controllers.