Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rigidbody or Transform Movement
#10
(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 ?
Reply


Messages In This Thread
Rigidbody or Transform Movement - by ATHellboy - 01-28-2020, 08:40 AM
RE: Rigidbody or Transform Movement - by _Aka_ - 01-28-2020, 03:29 PM
RE: Rigidbody or Transform Movement - by _Aka_ - 01-30-2020, 10:20 AM
RE: Rigidbody or Transform Movement - by _Aka_ - 01-30-2020, 07:47 PM
RE: Rigidbody or Transform Movement - by _Aka_ - 02-02-2020, 05:17 PM
RE: Rigidbody or Transform Movement - by ATHellboy - 02-03-2020, 09:00 PM
RE: Rigidbody or Transform Movement - by _Aka_ - 02-04-2020, 08:37 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Add noise to spline controller movement DekoGames 2 10 02-06-2024, 01:28 PM
Last Post: DekoGames
Question Setting instantiated object to spline, then starting movement? _RicO 3 9 06-28-2023, 06:01 PM
Last Post: _Aka_
  How do I make the computer ignore it's parent transform? eastes 3 7 04-06-2022, 12:16 PM
Last Post: _Aka_
  Connect knots to transform BanksySan 3 1,181 01-11-2021, 08:06 AM
Last Post: _Aka_

Forum Jump: