Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Moving Platform
#1
Hello,

I have the following setup.


Box with splineController that moves along 2 points in ping pong.

A script with which i get the velocity of the box with the bellow snip.

currentVelocity = (transform.position - previousPosition) / Time.deltaTime;
previousPosition = transform.position;

Then I add this velocity on my rigidbody after the i have set the its own movement velocity.

This works ok, until we are very near the next point, at which case, the rigidbody is pushed and displaced slightly.

I had the exact issue with using a custom rigidbody moving platform, but i resolved it by setting the execution order of the moving platform script to be lower than the players rigidbody.

I have tried all possible combinations, or at least most of them in terms of: getting the velocity in fixed update,update or late update, have the Target Component on Spline controller in rb and transform, locked rotations, etc.

I suspect is there is a component that runs the movement of the spline which runs after my players.
Or, that the controller snaps to end position when close enough.

Any ideas or guidance is appreciated.

Thank you in advance,
Kokoriko49
Reply
#2
Hi,
Here are multiple ideas that can help you.
  • Can you try to modify your setup so that it is similar to how the sphere is configured in scene 10_RBSplineController? Does this fix the issue?
  • If not, try setting up something like in scene 11_Rigidbody, which does not use a spline controller, but a new script that applies a force (in your case it should modify the velocity) in the direction of the spline's tangent.
  • Instead of computing the velocity by comparing positions, have you tried to set the spline controller's Speed property, and use that value, in combination with the spline tangent, to compute the velocity direction.
  • The issue is probably not that, but is the gravity still applied on your rigidbody?
Let me know if none of this worked.
Have a nice day
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
Admin Edit: Added code formating.

Hello again,

Checked both scenes, the setup is similar, but was not able to resolve the issue with any of the information i got from these scenes.

I have tried the tangent direction suggestion. It is slightly better, but still the same.

With tangent, the issue appears to be everytime we are nearing a point
With "Position" velocity, it seems that the issue is only present when the spline changes Direction from forward to backward and vice versa.



My code is as bellow.


Code:
float speed = controller.Speed;

if (controller.MovementDirection == MovementDirection.Backward)
speed *= -1;

Vector3 tangent = controller.Spline.GetTangent(controller.RelativePosition);

currentVelocity = tangent * speed;


I have also created a new game object with a script as bellow in order to ensure nothing from my players code creates the issue.

Code:
public class TestSplinePlatform : MonoBehaviour
{
   
    public Rigidbody rb;

    public SplineMovingPlatform splinePlatform;

    public bool addForward;

    private void FixedUpdate()
    {
        Vector3 direction = Vector3.zero;
        if (addForward)
        {
            direction = transform.forward;
        }
        direction += splinePlatform.currentVelocity;

        rb.velocity = direction;
    }

}


Issue unfortunately persists, when splineController nears the next point, there is some jingle/jitter behaviour on the rigidbody.

My Camera runs on LateUpdate
Have tried messing with the script priority order. Nothing worked.
Rigidbodies Interpolate is set to Interpolate for both the rigidbody of the splinecontroller and the player.
Have tried non and extrapolate, did not work

Any other suggestions?
Reply
#4
Hi

Try this:
Vector3 tangent = controller.Spline.GetTangentByDistance(controller.AbsolutePosition);
instead of this:
Vector3 tangent = controller.Spline.GetTangent(controller.RelativePosition);

If the issue persists, please send me a minimal reproduction case, with all the information needed for me to reproduce the issue.

Have a nice day
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
Hello again,

unfortunately the issue persists.

I have made a repro project, you can download it from the WeTransfer link bellow.

[Censored]

There are two objects, the platform and a capsule(Player)

Each have a script with some enum's / boolean's for testing the different approaches ( PreviousPosition, GetTangent, GetTangentByDistance etc. )


Appreciate your time.

Thank you
Reply
#6
Hi,
I will take a look at this today.
Have a nice day
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
Hi,
Found the cause of your issue. It is unrelated to Curvy Splines.

Your issue is that you compute the velocity from previous frame, and apply it to your capsule on the current frame. So you will have a delay. This delay, when the platform reaches the end of the spline and comes back, is translated as a "jitter" between the platform and the capsule.

Here is a fixed version of your code:

Code:
using FluffyUnderware.Curvy.Controllers;
using UnityEngine;

public class TestSplinePlatform : MonoBehaviour
{
    public Rigidbody rb;

    public SplineMovingPlatform splinePlatform;

    private void FixedUpdate()
    {
        Vector3 platformVelocity = GetPlatformVelocity();
        rb.velocity = platformVelocity;
    }

    private Vector3 GetPlatformVelocity()
    {
        float speed;
        {
            speed = splinePlatform.controller.Speed;
            if (splinePlatform.controller.MovementDirection == MovementDirection.Backward)
                speed *= -1;
        }

        return splinePlatform.controller.Spline.GetTangent(splinePlatform.controller.RelativePosition) * speed;
    }
}


Important point, make sure your script executes before the spline controller. (see Project Settings -> Script Execution Order).

If and when you feel like it, please leave a review for the asset, that helps a lot.
Have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#8
Hello again,

thanks for taking the time.

I have made the changes proposed, but the issue persists, not sure if i am doing anything wrong.

All i have done is simply change the TestSplinePlatformScript with the one you provided. Then I tried all different combinations with script execution order again.

Since depending on the actual setup, the jitter may not be noticeable, but still there. What will confirm this as resolved would be setting the splineController speed to something high(100 for example) and see if the players position would change relative to the platform.

On a standard rigidbody moving platform(kinematic and on Interpolate) that moves linearly from point to point, i can set the speed of the velocity to any high value, even 1000, and the position of the player will remain unchanged.

I do not care about the high speed, i just want to ensure no unwanted behavior.

Again, thank you for taking the time.
Reply
#9
Hi,
I fixed the jittering by:
  • Modifying your script to this:
    Code:
    public class CapsuleMover : MonoBehaviour
    {
        public Rigidbody rb;

        public Transform splinePlatform;

        private Vector3 previousPlatformPosition;

        void Start()
        {
            previousPlatformPosition = splinePlatform.transform.position;
        }

        private void FixedUpdate()
        {
            rb.position += splinePlatform.transform.position - previousPlatformPosition;
            previousPlatformPosition = splinePlatform.transform.position;
        }

    }
  • Configuring the controller to:
  1. Update In set to Fixed Update
  2. Target Component set to Transform

This way, I got smooth movement.
I hope this helped.
Have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Moving object down or up the spline using gravity velikizlivuk 6 20 07-26-2023, 10:06 PM
Last Post: _Aka_
  how to make fast moving controller go all the way to linear points?(curvy8) hawken 7 12 06-06-2023, 09:47 AM
Last Post: _Aka_
  Obstacle Moving Along the spline Chanon 1 7 06-13-2022, 04:13 PM
Last Post: _Aka_
  Possible to jump from platform to platform with Curvy splines? yun844 1 10 01-04-2022, 11:47 AM
Last Post: _Aka_

Forum Jump: