So i have made a CustomYieldInstruction, which works pretty good, problem here is, the speed of my CharacterController exceeds the given strength.
_config.Walk // 2f
the point here is, the Mathf.Towards function goes to a maximum value of “2f” but my velocity exceeds that which means that my character is moving quicker.
How do i get the CharacterController velocity?
Vector3 s = transform.InverseTransformDirection(_characterController.velocity);
debug_speed = s.z;
Any good solution to this?
I dont understand why CC.Move is moving my character faster then the given speed value.
Would appreciate any help
The CustomYield is used while interacting with any interactable object which needs the AI/Player to move towards a moveposition.
Imagine a Bench for example, in an RPG like Gothic/RIsen, i press a button to interact with and it automate the movement of my AI or Player towards the MovePoint where he needs to stand and to play his animation afterwards.
_owner.GetDistanceTo gets basically the distance from the interacting AI/Player towards the Destination (Bench / Bed / Fireplace etc…)
Line 35 makes the Speed go from 0 to 2 slowly (2f would be the max. walking speed).
Its like: currStrength = Mathf.MoveTowards(currStrength, maxStrength, recoveryRate * Time.deltaTime);
the Point of line 42. is to recover from the speed change, if the AI/Player reaches its destination the speed is not immedeatly at 0f, its maybe at 1f or 0.2… etc.
After that line the Animator sets the Speed in the Animator tab which makes the player walk at one place if the velocity is set above 0f, that way i just check, if we really reached the destination, set the finalSpeed to 0, its like an insurance.
The Use of CustomYield might be a bit too much, but i feel like not, we are doing an RPG and i do interactions in Coroutines which make me use of Yield Instructions, and they are very handy, instead of passing to much data into some Yield Instructions i can basically handle all the logic for its use case in it, and i can use it where ever i want.
protected override IEnumerator InteractWithPlayer()
{
_playerController = GetInteractingEntityComponent<PlayerController>();
CameraEventChannelSo.RaisePlayEvent(cameraMovePoint.position, cameraMovePoint.eulerAngles);
yield return new Turn(_playerController.transform, MovePoint.position, _turnDuration);
yield return new CCWalk(_playerController.GetComponent<CharacterController>(),
MovePoint.position,
_playerController.GetComponent<Animator>(),
_playerController.GetComponent<CharacterControllerAutomotive>().AutomotiveConfig);
yield return new Turn(_playerController.transform, GetTurnRotation(), _turnDuration);
TriggerAnimation();
yield return new WaitForFixedUpdate();
}
Dont get confused by the “GetComponent” its an overwritten function from me, caching the components in a list, that way i dont really have to get it from the GO but just filter it out of my list.
but lets simplify it and put it the easiest way possible and forget about the above snipped:
Here you go, i hope it helps, but the Vector towards function is not the problem i would say, since it does work, just the speed of which the CharacterController moves, is way to fast as the speed im given
I found a small function in my Helper class i wrote a while ago, with that, the movement speed is correct, but i still would love to figure it out with CharacterController,
here is the working code without the CharacterController: