Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rigidbody or Transform Movement
#1
I want to make something like Sonic Forces.

Because there are obstacles and hero attacks, triggers are really important. So I think using Rigidbody for moving a character on a track (spline) is important. Do you agree ?
Now I want to know Spline Controller is based on Transfrom movement or Rigidbody ? and if it is not how can I make something like spline controller based on physics and rigidbody movement and stuff (Like jump).
Reply
#2
Hi,
Spline controller moves the transform, but then Unity synchronizes the position of the rigidbody with the one of the transform, so it end up being the same. Please keep in mind that the rigibody is not moved through applied forces.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#3
For implementing jump, Does it make sense to use OffsetRadius ?
Just one problem which I think about by changing OffsetRadius by lerping is when jumping happen between straight way and slope. Do you know what I mean ?
So I'm thinking about making something similar to rigidbody.velocity, I mean have gravity and velocity together but not real physics one. Do I think correctly ? and have you implemented this in Curvy before ?

[Edit]
As I see using OffsetRadius is not good for jumping because jumping should be unrelated to the ground after start jumping. Do you have any idea ?
Reply
#4
Using OffsetRadius or not is I think just a detail. The important thing is to use like you said pseudo gravity and velocity to have a good looking jump. Once you calculated the height using that, you can either apply it by modifying directly the transform, or consider the difference between the desired height and the spline's height, and apply that through the OffsetRadius

FYI, OffsetRadius is used for jumping in example scene 50_EndlessRunner
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#5
(01-30-2020, 10:20 AM)_Aka_ Wrote: Using OffsetRadius or not is I think just a detail. The important thing is to use like you said pseudo gravity and velocity to have a good looking jump. Once you calculated the height using that, you can either apply it by modifying directly the transform, or consider the difference between the desired height and the spline's height, and apply that through the OffsetRadius

FYI, OffsetRadius is used for jumping in example scene 50_EndlessRunner

As I figured out, OffsetRadius is based on Y axis of spline. So using OffsetRadius doesn't help me to implement jump and fall.

I've checked out scene 50_EndlessRunner but it is not a good jump really. As I said when the character is on air it should not depends on Y axis of spline or ground if it depends on Y axis then jumping effect is incorrect. As you can see in this gif from scene 50_EndlessRunner (I just change the spline a little bit for showing incorrect jumping): https://gyazo.com/acf01a2dbb59e06e086e75e5f821928f
Reply
#6
So you will have to use an inherited class from Curvy Spline where you can override the updating methods and implement your own jumping logic
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#7
(01-30-2020, 07:47 PM)_Aka_ Wrote: So you will have to use an inherited class from Curvy Spline where you can override the updating methods and implement your own jumping logic

Thanks.
Any thing to consider when implementing jumping logic ? Could you tell me what methods I should work on ?
Reply
#8
It is really hard to understand what systems are implemented for CurvyController and SplineController. There is no explanation about writing custom controller (There is a page but it's not really enough, actually I don't see any good points)
Could you help me which parts I should consider for writing the jump logic which I want ? (And I think it is really necessary in your package)
Reply
#9
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 ;
       }
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#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


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: