(02-02-2020, 05:17 PM)_Aka_ Wrote: Hi,
Sorry I missed your ealier message.
What to override really depends on how you want to implement things. You might want to override InitializedApplyDeltaTime with something like this:
Code:protected override void InitializedApplyDeltaTime(float deltaTime)
{
base.InitializedApplyDeltaTime(deltaTime);
Vector3 jumpDisplacement = ....;
Transform.position += jumpDisplacement ;
}
I'm really stuck in it.
First let me explain what I want to achieve.
I assumed couple of things for implementing jump and fall.
First, Y of jumping should be unrelated to height of the spline because if it is then it looks artificial. (You know what I mean ?)
Second, on downward hill, upward hill or any surface there should not be forward movement in jumping. So I want to ignore any forward movement in jumping.
And third, when the path rotates to the sides (I mean when it is rotated around Z axis), jumping should be in that direction.
So I'm seeking correct direction for handling this situation. transform.up is a good direction but in downhill and uphill there is a forward movement which I don't want it . I tried many directions but none of them supports all of these situations.
I tried to override ComputeTargetPositionAndRotation method.
The code in CharacterController which inherits SplineController :
Code:
protected override void ComputeTargetPositionAndRotation(out Vector3 targetPosition, out Vector3 targetUp, out Vector3 targetForward)
{
Vector3 tempTargetUp;
Vector3 tempTargetForward;
if (_locomotionHandler == null)
{
Vector3 tempTargetPosition;
base.ComputeTargetPositionAndRotation(out tempTargetPosition, out tempTargetUp, out tempTargetForward);
targetPosition = tempTargetPosition;
targetUp = tempTargetUp;
targetForward = tempTargetForward;
return;
}
base.ComputeTargetPositionAndRotation(out _locomotionHandler.tempTargetPosition, out tempTargetUp, out tempTargetForward);
if (_performStateMachineContext.CurrentState == _performStateMachineContext.RelatedStates.jump ||
_performStateMachineContext.CurrentState == _performStateMachineContext.RelatedStates.fall)
{
_locomotionHandler.ApplyGravity();
targetPosition = new Vector3(
_locomotionHandler.tempTargetPosition.x + _locomotionHandler.TotalDeltaJumpPosition.x,
transform.position.y + _locomotionHandler.DeltaJumpPosition.y,
_locomotionHandler.tempTargetPosition.z + _locomotionHandler.TotalDeltaJumpPosition.z);
}
else
{
targetPosition = _locomotionHandler.tempTargetPosition;
}
targetUp = tempTargetUp;
targetForward = tempTargetForward;
}
The code from CharacterLocomotionHandler:
Code:
public void Jump()
{
TotalDeltaJumpPosition = Vector3.zero;
JumpDirection =_transform.up;
JumpVelocity = _jumpTakeOffSpeed * JumpDirection;
}
public void ApplyGravity()
{
JumpVelocity += _gravity * JumpDirection * Time.deltaTime;
DeltaJumpPosition = JumpVelocity * Time.deltaTime;
TotalDeltaJumpPosition += DeltaJumpPosition;
}
They are not all the codes but I think it is certain what I do.
Do I do something wrong ? Any idea ?