Posts: 46
Threads: 13
Joined: Jan 2020
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).
Posts: 2,113
Threads: 92
Joined: Jun 2017
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 helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Posts: 46
Threads: 13
Joined: Jan 2020
01-29-2020, 12:58 PM
(This post was last modified: 01-29-2020, 02:59 PM by ATHellboy.)
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 ?
Posts: 2,113
Threads: 92
Joined: Jun 2017
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 helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Posts: 46
Threads: 13
Joined: Jan 2020
(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
Posts: 2,113
Threads: 92
Joined: Jun 2017
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 helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Posts: 46
Threads: 13
Joined: Jan 2020
(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 ?
Posts: 46
Threads: 13
Joined: Jan 2020
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)
Posts: 2,113
Threads: 92
Joined: Jun 2017
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 helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Posts: 46
Threads: 13
Joined: Jan 2020
02-03-2020, 09:00 PM
(This post was last modified: 02-04-2020, 06:02 AM by ATHellboy.)
(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 ?