void rotate(Vector3 velocity) { if (specialDirection != Vector3.zero) { velocity += DirectionVector.getVector(this.direction) * 2f; } velocity.y = 0f; Quaternion lookRotation = Quaternion.identity; if (velocity != Vector3.zero) { lookRotation = Quaternion.LookRotation(velocity); } float angle = lookRotation.y - this.transform.rotation.y; if (this.lastLookRotation != lookRotation) { this.rotating = 0f; this.lastRotation = this.transform.rotation; this.lastLookRotation = lookRotation; } else if (this.rotating != 1f) { this.rotating += Time.deltaTime * this.speed; } if (this.rotating > 1f) { this.rotating = 1f; } this.transform.rotation = Quaternion.Lerp(lastRotation, lookRotation, this.rotating * 2f); }
void debug() { Debug.DrawLine(this.transform.position, this.transform.position + DirectionVector.getVector(this.direction) * 2f, Color.red); this.debugLines.Add(this.transform.position); for (int i = 1; i < this.debugLines.Count; i++) { Debug.DrawLine(this.debugLines[i - 1], this.debugLines[i], Color.blue); } }
void move() { if (this.jumping >= 0f) { this.Jumping(); return; } Vector3 beforePosition = this.transform.position; this.transform.Translate(this.directionVector * this.getSpeed() * Time.deltaTime, Space.World); Vector3 velocity = this.transform.position - beforePosition; this.rotate(velocity); if (!this.runningStraight) { Vector3 currentOffsetVector = this.calculateLineOffset(this.transform.position); float a = 0f; float b = 0f; if (direction == Direction.Forward || direction == Direction.Backward) { a = this.lastOffsetVector.x; b = currentOffsetVector.x; } else if (direction == Direction.Right || direction == Direction.Left) { a = this.lastOffsetVector.z; b = currentOffsetVector.z; } this.runningStraight = (a >= 0f && b <= 0f) || (a <= 0f && b >= 0f); if (this.runningStraight) { this.directionVector = this.specialDirection != Vector3.zero ? this.specialDirection : DirectionVector.getVector(this.direction); } } }
public IAction CreateAction(ActionType type, IAction actionRef = null, Direction actionDirection = Direction.None) { if (type == null) { return(null); } GameObject actionObject = GameObject.CreatePrimitive(PrimitiveType.Cube); actionObject.AddComponent <BuildingBlock>(); actionObject.name = type.ToString(); this.AddToLevel(actionObject); actionObject.transform.position = Vector3.zero; actionObject.transform.rotation = Quaternion.identity; IAction ret = null; switch (type) { case ActionType.Run: { actionObject.GetComponent <MeshRenderer>().sharedMaterial = AssetDatabase.LoadAssetAtPath("Assets/Materials/Builder/Run.mat", typeof(Material)) as Material; ret = actionObject.AddComponent <ActionRun>(); break; } case ActionType.SafetyNetForRun: { actionObject.GetComponent <MeshRenderer>().sharedMaterial = AssetDatabase.LoadAssetAtPath("Assets/Materials/Builder/SafetyNetForRun.mat", typeof(Material)) as Material; ret = actionObject.AddComponent <ActionSafetyNetForRun>(); (ret as ActionSafetyNetForRun).actionRun = (ActionRun)actionRef; ((ActionRun)actionRef).safetyNet = actionObject; actionObject.transform.localScale = ActionSafetyNetForRun.boxSize; break; } case ActionType.Death: { actionObject.GetComponent <MeshRenderer>().sharedMaterial = AssetDatabase.LoadAssetAtPath("Assets/Materials/Builder/Death.mat", typeof(Material)) as Material; ret = actionObject.AddComponent <ActionDeath>(); break; } case ActionType.Slide: { actionObject.GetComponent <MeshRenderer>().sharedMaterial = AssetDatabase.LoadAssetAtPath("Assets/Materials/Builder/Slide.mat", typeof(Material)) as Material; ret = actionObject.AddComponent <ActionSlide>(); actionObject.transform.localScale = new Vector3(.25f, .25f, .25f); break; } case ActionType.Jump: { actionObject.GetComponent <MeshRenderer>().sharedMaterial = AssetDatabase.LoadAssetAtPath("Assets/Materials/Builder/Jump.mat", typeof(Material)) as Material; ret = actionObject.AddComponent <ActionJump>(); break; } case ActionType.TriggerRun: { actionObject.GetComponent <MeshRenderer>().sharedMaterial = AssetDatabase.LoadAssetAtPath("Assets/Materials/Builder/TriggerRun.mat", typeof(Material)) as Material; ret = actionObject.AddComponent <ActionTriggerRun>(); break; } case ActionType.Translate: { actionObject.GetComponent <MeshRenderer>().sharedMaterial = AssetDatabase.LoadAssetAtPath("Assets/Materials/Builder/Translate.mat", typeof(Material)) as Material; ret = actionObject.AddComponent <ActionTranslate>(); break; } case ActionType.None: { actionObject.GetComponent <MeshRenderer>().sharedMaterial = AssetDatabase.LoadAssetAtPath("Assets/Materials/Builder/Direction.mat", typeof(Material)) as Material; ret = actionObject.AddComponent <ActionNone>(); actionObject.transform.localScale = new Vector3(.25f, .25f, .25f); break; } default: break; } if (actionRef != null) { if (ret != null) { this.LinkActions(actionRef, ret, actionDirection); } actionObject.transform.position = (actionRef as MonoBehaviour).transform.position + DirectionVector.getVector(actionDirection); } Selection.activeGameObject = actionObject; return(ret); }