private void Awake() { targeter = GetComponent <Targeter>(); targetRotation = GetComponent <TargetRotation>(); enemyMovement = GetComponent <EnemyMovement>(); rb = GetComponent <Rigidbody2D>(); }
// PUBLIC METHODS: ------------------------------------------------------------------------ public void SetDirection(Vector3 direction, TargetRotation rotation = null) { this.desiredDirection = direction; if (rotation != null) { } }
public void Stop(TargetRotation rotation = null, UnityAction callback = null) { this.SetTarget( this.characterLocomotion.characterController.transform.position, rotation, 0f, callback ); }
// PUBLIC METHODS: --------------------------------------------------------------------------------------------- public void SetTarget(Ray ray, TargetRotation rotation = null, UnityAction callback = null) { RaycastHit hit; int layerMask = Physics.DefaultRaycastLayers; QueryTriggerInteraction queryTrigger = QueryTriggerInteraction.Ignore; if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask, queryTrigger)) { this.SetTarget(hit.point, rotation, callback); } }
// PUBLIC METHODS: ------------------------------------------------------------------------ public void SetTarget(Ray ray, LayerMask layerMask, TargetRotation rotation, float stopThreshold, UnityAction callback = null) { RaycastHit hit; QueryTriggerInteraction queryTrigger = QueryTriggerInteraction.Ignore; if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask, queryTrigger)) { this.SetTarget(hit.point, rotation, stopThreshold, callback); } }
protected override YAMLMappingNode ExportYAMLRoot(IExportContainer container) { YAMLMappingNode node = base.ExportYAMLRoot(container); node.Add(ConnectedBodyName, ConnectedBody.ExportYAML(container)); node.Add(AnchorName, Anchor.ExportYAML(container)); node.Add(AxisName, Axis.ExportYAML(container)); node.Add(AutoConfigureConnectedAnchorName, AutoConfigureConnectedAnchor); node.Add(ConnectedAnchorName, ConnectedAnchor.ExportYAML(container)); node.AddSerializedVersion(GetSerializedVersion(container.ExportVersion)); node.Add(SecondaryAxisName, SecondaryAxis.ExportYAML(container)); node.Add(XMotionName, (int)XMotion); node.Add(YMotionName, (int)YMotion); node.Add(ZMotionName, (int)ZMotion); node.Add(AngularXMotionName, (int)AngularXMotion); node.Add(AngularYMotionName, (int)AngularYMotion); node.Add(AngularZMotionName, (int)AngularZMotion); node.Add(LinearLimitSpringName, LinearLimitSpring.ExportYAML(container)); node.Add(LinearLimitName, LinearLimit.ExportYAML(container)); node.Add(AngularXLimitSpringName, AngularXLimitSpring.ExportYAML(container)); node.Add(LowAngularXLimitName, LowAngularXLimit.ExportYAML(container)); node.Add(HighAngularXLimitName, HighAngularXLimit.ExportYAML(container)); node.Add(AngularYZLimitSpringName, AngularYZLimitSpring.ExportYAML(container)); node.Add(AngularYLimitName, AngularYLimit.ExportYAML(container)); node.Add(AngularZLimitName, AngularZLimit.ExportYAML(container)); node.Add(TargetPositionName, TargetPosition.ExportYAML(container)); node.Add(TargetVelocityName, TargetVelocity.ExportYAML(container)); node.Add(XDriveName, XDrive.ExportYAML(container)); node.Add(YDriveName, YDrive.ExportYAML(container)); node.Add(ZDriveName, ZDrive.ExportYAML(container)); node.Add(TargetRotationName, TargetRotation.ExportYAML(container)); node.Add(TargetAngularVelocityName, TargetAngularVelocity.ExportYAML(container)); node.Add(RotationDriveModeName, (int)RotationDriveMode); node.Add(AngularXDriveName, AngularXDrive.ExportYAML(container)); node.Add(AngularYZDriveName, AngularYZDrive.ExportYAML(container)); node.Add(SlerpDriveName, SlerpDrive.ExportYAML(container)); node.Add(ProjectionModeName, (int)ProjectionMode); node.Add(ProjectionDistanceName, ProjectionDistance); node.Add(ProjectionAngleName, ProjectionAngle); node.Add(ConfiguredInWorldSpaceName, ConfiguredInWorldSpace); node.Add(SwapBodiesName, SwapBodies); node.Add(BreakForceName, BreakForce); node.Add(BreakTorqueName, BreakTorque); node.Add(EnableCollisionName, EnableCollision); node.Add(EnablePreprocessingName, EnablePreprocessing); node.Add(MassScaleName, MassScale); node.Add(ConnectedMassScaleName, ConnectedMassScale); return(node); }
public void SetTarget(Ray ray, LayerMask layerMask, TargetRotation rotation, float stopThreshold, UnityAction callback = null) { QueryTriggerInteraction queryTrigger = QueryTriggerInteraction.Ignore; int hitCount = Physics.RaycastNonAlloc( ray, this.hitBuffer, Mathf.Infinity, layerMask, queryTrigger ); if (hitCount > 0) { this.SetTarget(this.hitBuffer[0].point, rotation, stopThreshold, callback); } }
private void Slowing(float distanceToDestination) { float tDistance = 1f - (distanceToDestination / SLOW_THRESHOLD); Quaternion targetRotation = this.characterLocomotion.character.transform.rotation; if (this.targetRotation.hasRotation && this.characterLocomotion.faceDirection == CharacterLocomotion.FACE_DIRECTION.MovementDirection) { targetRotation = this.targetRotation.rotation; } this.characterLocomotion.character.transform.rotation = Quaternion.Lerp( this.characterLocomotion.character.transform.rotation, targetRotation, tDistance ); }
public void SetTarget(Vector3 position, TargetRotation rotation, float stopThreshold, UnityAction callback = null) { this.move = true; this.usingNavmesh = false; this.stopThreshold = Mathf.Max(stopThreshold, STOP_THRESHOLD); this.onFinishCallback = callback; if (this.characterLocomotion.canUseNavigationMesh) { NavMeshHit hit; if (NavMesh.SamplePosition(position, out hit, 1.0f, NavMesh.AllAreas)) { position = hit.position; } this.path = new NavMeshPath(); bool pathFound = NavMesh.CalculatePath( this.characterLocomotion.characterController.transform.position, position, NavMesh.AllAreas, this.path ); if (pathFound) { Debug.DrawLine(position, position + Vector3.up, Color.green, 0.1f); this.usingNavmesh = true; this.characterLocomotion.navmeshAgent.enabled = true; this.characterLocomotion.navmeshAgent.updatePosition = true; this.characterLocomotion.navmeshAgent.updateUpAxis = true; this.characterLocomotion.navmeshAgent.isStopped = false; this.characterLocomotion.navmeshAgent.SetPath(this.path); } } this.targetPosition = position; this.targetRotation = rotation ?? new TargetRotation(); }
private void Update() { CoordinateSystem cs = this.GetCurrentCoordinateSystem(); // Get the player's movement vector. Vector3 movement = this.GetMovement(cs.X, cs.Y, cs.Z); // Move the player. Rigidbody rb = this.GetComponent <Rigidbody>(); rb.MovePosition(rb.position + movement); Vector3 targetRotation = new Vector3(this.transform.rotation.eulerAngles.x, this.mainCamera.transform.rotation.eulerAngles.y, this.transform.rotation.eulerAngles.z); TargetRotation tr = this.GetComponent <TargetRotation>(); tr.SetTargetRotation(targetRotation); this.axisObject.transform.position = this.transform.position; this.axisObject.transform.Find("X").localPosition = cs.X; this.axisObject.transform.Find("Y").localPosition = cs.Y; this.axisObject.transform.Find("Z").localPosition = cs.Z; // For sphere gravity this.gravity = -rb.position.normalized; // Let gravity affect the player. rb.AddForce(this.gravity * rb.mass, ForceMode.Force); if (Input.GetKey(KeyCode.Keypad7)) { this.gravity = Vector3.down; } else if (Input.GetKey(KeyCode.Keypad9)) { this.gravity = Vector3.up; } else if (Input.GetKey(KeyCode.Keypad8)) { this.gravity = Vector3.forward; } else if (Input.GetKey(KeyCode.Keypad5)) { this.gravity = Vector3.back; } else if (Input.GetKey(KeyCode.Keypad4)) { this.gravity = Vector3.left; } else if (Input.GetKey(KeyCode.Keypad6)) { this.gravity = Vector3.right; } else if (Input.GetKey(KeyCode.Keypad2)) { this.gravity = new Vector3(0.0f, -2.0f, -1.0f).normalized; } else if (Input.GetKey(KeyCode.Keypad0)) { this.gravity = Random.onUnitSphere; } //this.axisObject.transform.localScale = new Vector3(cs.X.magnitude, cs.Y.magnitude, cs.Z.magnitude); }
public static Quaternion TargetRotationToQuaternion(this TargetRotation targetRotation) { return(new Quaternion(targetRotation.X, targetRotation.Y, targetRotation.Z, targetRotation.W)); }