public void OrientAlign() { // Get the vector to the target to determine target Orientation var diff = currentGoal - transform.position; diff = diff.normalized; float targetOrientation; if (diff.magnitude > 0f) { targetOrientation = Mathf.Atan2(-diff.z, diff.x); } else { targetOrientation = KinematicBody.getOrientation(); } // Calculate the needed rotation to reach the target; var rotation = targetOrientation - KinematicBody.getOrientation(); rotation = Kinematic.mapToRange(rotation); var rotationSize = Mathf.Abs(rotation); if (rotationSize < angularGoalRadius) { torque = 0f; tiltAmountSideways = 0f; return; } float targetRotation; // if we're outside the slow Radius if (rotationSize > angularSlowRadius) { targetRotation = SP.MAXROTATION; } else { targetRotation = SP.MAXROTATION * rotationSize / slowRadius; } // Final target rotation combines speed (already in variable) with rotation direction targetRotation = targetRotation * rotation / rotationSize; torque = targetRotation - KinematicBody.getRotation(); torque = torque / alignTime; var angularAcceleration = Mathf.Abs(torque); if (angularAcceleration > SP.MAXANGULAR) { torque = torque / angularAcceleration; torque = torque * SP.MAXANGULAR; } }
//public virtual DynoSteering getSteering(); // Update is called once per frame public DynoSteering getSteering() { goal = goalObject.getGoal(); ds = new DynoSteering(); //goal.position - transform.position; targetOrientation = charRigidBody.getNewOrientation(goal.position - transform.position); //rotation = goal.eulerAngles; rotation = targetOrientation - charRigidBody.getOrientation(); rotation = Kinematic.mapToRange(rotation); rotationSize = Mathf.Abs(rotation); if (rotationSize < goalRadius) { return(ds); } // if we're outside the slow Radius if (rotationSize > slowRadius) { targetRotation = sp.MAXROTATION; } else { targetRotation = sp.MAXROTATION * rotationSize / slowRadius; } // Final target rotation combines speed (already in variable) with rotation direction targetRotation = targetRotation * rotation / rotationSize; ds.torque = targetRotation - charRigidBody.getRotation(); ds.torque = ds.torque / time_to_target; angularAcceleration = Mathf.Abs(ds.torque); if (angularAcceleration > sp.MAXANGULAR) { ds.torque = ds.torque / angularAcceleration; ds.torque = ds.torque * sp.MAXANGULAR; } return(ds); }
public void Align() { var targetOrientation = KinematicBody.getNewOrientation(currentGoal - transform.position); //rotation = goal.eulerAngles; var rotation = targetOrientation - KinematicBody.getOrientation(); rotation = Kinematic.mapToRange(rotation); var rotationSize = Mathf.Abs(rotation); if (rotationSize < angularGoalRadius) { torque = 0f; tiltAmountSideways = 0f; return; } float targetRotation; // if we're outside the slow Radius if (rotationSize > angularSlowRadius) { targetRotation = SP.MAXROTATION; } else { targetRotation = SP.MAXROTATION * rotationSize / slowRadius; } tiltAmountSideways = targetRotation; // Final target rotation combines speed (already in variable) with rotation direction targetRotation = targetRotation * rotation / rotationSize; torque = targetRotation - KinematicBody.getRotation(); torque = torque / alignTime; var angularAcceleration = Mathf.Abs(torque); if (angularAcceleration > SP.MAXANGULAR) { torque = torque / angularAcceleration; torque = torque * SP.MAXANGULAR; } }