/// <summary> /// Utility method for quantising a samples of sensor readings into input vectors. /// </summary> /// <param name="sensorReadingsSamples">A list of sensor reading samples to be quantised.</param> /// <param name="sensorObjects">Array of sensor objects associated with the sensor readings.</param> /// <returns>An array of input vectors which were created from quantising the provided samples of sensor readings.</returns> public static InputVector[] QuantiseSensorReadingsSamples(List <BaseSensorReading>[] sensorReadingsSamples, Sensor[] sensorObjects) { InputVector[] inputVectors = new InputVector[sensorReadingsSamples.Length]; for (int i = 0; i < sensorReadingsSamples.Length; i++) { InputVector anInputVector; /* * This part probably could be coded better. The previous input vector may influence the value * of the next input vector. For example, presence sensor values during quantisation. */ if (i > 0) { anInputVector = QuantiseSensorReadingsSample(sensorReadingsSamples[i], sensorObjects, inputVectors[i - 1]); } else { anInputVector = QuantiseSensorReadingsSample(sensorReadingsSamples[i], sensorObjects, null); } inputVectors[i] = anInputVector; } return(inputVectors); }
/// <summary> /// Utility method for quantising a single sample of sensor readings into a input vector. /// </summary> /// <param name="sensorReadings">Sensor readings to be quantised.</param> /// <param name="sensorObjects">Array of sensor objects associated with the sensor readings.</param> /// <param name="previousInputVector">Input vector from the previous sample period.</param> /// <returns></returns> private static InputVector QuantiseSensorReadingsSample(List <BaseSensorReading> sensorReadings, Sensor[] sensorObjects, InputVector previousInputVector) { // Create and setup input vector, which will contain all the quantised data tuples InputVector anInputVector = CreateInputVector(sensorObjects); // Setup data structure for sensor name to sensor reading list lookups - also byproducts: input vector output and sensor names found in sensor readings List <string> sensorNamesFoundInSensorReadings; var sensorNameToSensorReadings = CreateSensorReadingsDictionary(sensorReadings, out sensorNamesFoundInSensorReadings, ref anInputVector); // Reference quantised values for each sensor name foreach (string sensorName in sensorNamesFoundInSensorReadings) { List <BaseSensorReading> sensorReadingsOfSensorName = sensorNameToSensorReadings[sensorName]; // Reference the previous tuple value float previousTupleValue = 0f; if (previousInputVector != null) { InputVectorTuple previousInputVectorTuple = previousInputVector.FindInputVectorTuple(sensorName); if (previousInputVectorTuple != null) { previousTupleValue = previousInputVectorTuple.sensorValue; } } // Construct new tuple with quantised value InputVectorTuple newInputVectorTuple = anInputVector.FindInputVectorTuple(sensorName); newInputVectorTuple.sensorValue = QuantiseSensorReadings(sensorReadingsOfSensorName, newInputVectorTuple.sensorType, previousTupleValue); } return(anInputVector); }
/// <summary> /// Move charatcer based on input values. /// </summary> protected virtual void Move() { if (InputVector.sqrMagnitude > 1) { InputVector.Normalize(); } RelativeInputVector = m_Transform.TransformDirection(InputVector); //m_DeltaYRotation = 0; m_Velocity = RelativeInputVector; m_MoveDirection = m_Velocity * m_DeltaTime; float turnAngle = 0; switch (m_MovementType) { case (MovementType.Adventure): var direction = Mathf.Abs(InputVector.z) > 0 ? InputVector.x : -InputVector.x; float targetAngle = Mathf.Atan2(direction, Mathf.Abs(InputVector.z)); targetAngle *= Mathf.Rad2Deg * m_RotationSpeed; m_DeltaYRotation = Mathf.SmoothDampAngle(m_DeltaYRotation, targetAngle, ref m_RotationSmoothDamp, 0.15f); //CharacterDebug.Log("targetAngle", targetAngle); break; case (MovementType.Combat): Vector3 localDir = m_Transform.InverseTransformDirection(LookDirection); m_DeltaYRotation = Mathf.Atan2(localDir.x, localDir.z) * Mathf.Rad2Deg * m_RotationSpeed; //m_DeltaYRotation = Mathf.SmoothDampAngle(m_DeltaYRotation, targetAngle, ref m_RotationSmoothDamp, 0.15f) * m_RotationSpeed; break; } Vector3 axisSign = Vector3.Cross(LookDirection, m_Transform.forward); turnAngle = Vector3.Angle(m_Transform.forward, LookDirection) * (axisSign.y >= 0 ? -1f : 1f); CharacterDebug.Log("m_DeltaYRotation", m_DeltaYRotation); CharacterDebug.Log("turnAngle", turnAngle); Moving = Mathf.Abs((m_Rigidbody.position - m_PreviousPosition).sqrMagnitude) > 0; m_Rigidbody.angularDrag = InputVector.sqrMagnitude > 0 ? 0.05f : m_Mass; }
/// <summary> /// Helper method creating an input vector which represents a sample of sensor readings. /// </summary> /// <param name="sensorObjects">Array of sensor objects associated with sensor readings.</param> /// <returns></returns> private static InputVector CreateInputVector(Sensor[] sensorObjects) { InputVector anInputVector = new InputVector() { InputTuples = new InputVectorTuple[sensorObjects.Length] }; for (int i = 0; i < sensorObjects.Length; i++) { anInputVector.InputTuples[i] = new InputVectorTuple() { sensorName = sensorObjects[i].SensorName, sensorType = sensorObjects[i].GetSensorType(), sensorValue = 0f }; } return(anInputVector); }
public override string ToString() { string str = InputVector.ToString(); str += " "; for (int i = 0; i != 15; ++i) { if (KeysState[i]) { str += "1"; } else { str += "0"; } if (i % 3 == 2) { str += " "; } } return(str); }
public void MoveState(Slot[] wieldedSlotSet) { InputVector.x = Input.GetActionStrength("ui_right") - Input.GetActionStrength("ui_left"); InputVector.y = Input.GetActionStrength("ui_down") - Input.GetActionStrength("ui_up"); InputVector = InputVector.Normalized(); if (InputVector != Vector2.Zero) { DashVector = InputVector; animationTree.Set("parameters/Idle/blend_position", InputVector); animationTree.Set("parameters/Run/blend_position", InputVector); animationTree.Set("parameters/Attack/blend_position", InputVector); animationTree.Set("parameters/Dash/blend_position", InputVector); playerAnimationState.Travel("Run"); MoveAndSlide(InputVector * MoveSpeed); } else { playerAnimationState.Travel("Idle"); InputVector = MoveAndSlide(Vector2.Zero); } if (Input.IsActionJustPressed("ui_ability1")) { if (wieldedSlotSet[0].AssignedPin != null && !wieldedSlotSet[0].AssignedPin.Passive) { AbilityPrime(wieldedSlotSet, 1); } } if (Input.IsActionJustPressed("ui_ability2")) { if (wieldedSlotSet[1].AssignedPin != null && !wieldedSlotSet[1].AssignedPin.Passive) { AbilityPrime(wieldedSlotSet, 2); } } if (Input.IsActionJustPressed("ui_ability3")) { if (wieldedSlotSet[2].AssignedPin != null && !wieldedSlotSet[2].AssignedPin.Passive) { AbilityPrime(wieldedSlotSet, 3); } } if (Input.IsActionJustPressed("ui_ability4")) { if (wieldedSlotSet[3].AssignedPin != null && !wieldedSlotSet[3].AssignedPin.Passive) { AbilityPrime(wieldedSlotSet, 4); } } if (Input.IsActionJustPressed("ui_ability5")) { if (wieldedSlotSet[4].AssignedPin != null && !wieldedSlotSet[4].AssignedPin.Passive) { AbilityPrime(wieldedSlotSet, 5); } } if (Input.IsActionJustPressed("ui_ability6")) { if (wieldedSlotSet[5].AssignedPin != null && !wieldedSlotSet[5].AssignedPin.Passive) { AbilityPrime(wieldedSlotSet, 6); } } if (Input.IsActionJustPressed("ui_dash")) { state = Global.BehaviorState.STATE_DASH; } }
/// <summary> /// Helper method for creating a dictionary for sensor readings. The dictionary is used to separate /// the sensor readings with the respective sensors. /// </summary> /// <param name="sensorReadings">Sensor readings used for creating the dictionary.</param> /// <param name="sensorNamesList">Referenced list of sensor names which are identified from the sensor readings.</param> /// <param name="anInputVector">Referenced input vector whose output is updated from the sensor readings.</param> /// <returns>Dictionary mapping of sensor names to sensor readings.</returns> private static Dictionary <string, List <BaseSensorReading> > CreateSensorReadingsDictionary(List <BaseSensorReading> sensorReadings, out List <string> sensorNamesList, ref InputVector anInputVector) { var sensorNameToSensorReadings = new Dictionary <string, List <BaseSensorReading> >(); sensorNamesList = new List <string>(); foreach (BaseSensorReading aSensorReading in sensorReadings) { if (!sensorNameToSensorReadings.ContainsKey(aSensorReading.sensorName)) { sensorNameToSensorReadings.Add(aSensorReading.sensorName, new List <BaseSensorReading>()); sensorNamesList.Add(aSensorReading.sensorName); } sensorNameToSensorReadings[aSensorReading.sensorName].Add(aSensorReading); anInputVector.SetOutputUsingBookmarkName(aSensorReading.sensorBookmarkName); } return(sensorNameToSensorReadings); }