Pushing player along path [Solved]

Hey there forum,

As of now, I haven’t figured out how to push the player alongside the uv scroll of a mesh.
The player stays perfectly stationary when not pushing any input. So my question is, what would be the best way to return the angle of this geometry? This is because the water isn’t simply going straight but has angles and curves. Now I think about that, I did recently watch a Mario Kart tutorial on Youtube that allows AI to move along a path/spline. Anyone knows a good way to achieve this? Thanks in advance!

Probably easiest to match a spline perfectly with the geometry and follow that spline. The asset store has lots of bezier spline free projects available, and there are others available online.

If you insist on using the actual texture, you’d have to raycast to it, have a collider on it, then read the barycentric coorindates at that hitpoint, then offset that by any UV coordinate scrolling going on to decide how much to move. It’s probably easy to just make a spline!

Yeah I tried running a barycentric script in runtime and it was very costly (went from 470fps to around 200) which is unacceptable. I’ll see what I can do with a spline. I mean, creating the spline isn’t exactly a difficulty. Making the character look for it’s nearest forward transform is more challenging. :hushed:

Just have a trigger collider that keeps pushing any players inside it along it’s Z or X axis or some such and add a bunch of those along the river, rotating them to match the flow.

Found the solution.

using UnityEngine;
using PathCreation;
using KinematicCharacterController.Player;
public class PushPlayerAlongPath : MonoBehaviour
{
    [SerializeField] private PathCreator Path;
    [SerializeField] private float StrengthOfCurrent;
    [SerializeField] private GameObject WaterSurface;
    [SerializeField] private WaterTrigger Trigger;

    private GameObject PlayerObj;
    private PlayerController PlayerController;
    private GameObject PathHelper;
    private Vector3 TargetPosition;
    private Quaternion TargetRotation;
    private void Awake()
    {
        PlayerObj = GameSession.Instance.PlayerObj;
        PlayerController = PlayerObj.GetComponent<PlayerController>();
        PathHelper = new GameObject();
        PathHelper.name = "Path Helper";
        UpdatePathPosition();
    }
    private void FixedUpdate()
    {
        TargetPosition = Path.path.GetClosestPointOnPath(PlayerObj.transform.position);
        PathHelper.transform.position = TargetPosition;
        if (Trigger.CheckIfActive)
        {
            UpdatePathPosition();
            PushPlayer();
        } 
    }
    private void UpdatePathPosition()
    {
        var Dist = Path.path.GetClosestDistanceAlongPath(PlayerObj.transform.position);
        TargetRotation = Quaternion.LookRotation(Path.path.GetDirectionAtDistance(Dist, EndOfPathInstruction.Stop));
        TargetRotation.z *= 0;
        TargetRotation.x *= 0;
        PathHelper.transform.rotation = Quaternion.Lerp(PathHelper.transform.rotation, TargetRotation, Time.deltaTime * 16.0f);
        TargetPosition.y = WaterSurface.transform.position.y;
    }
    private void PushPlayer()
    {
        PlayerController.Motor.MoveCharacter(PlayerObj.transform.position+PathHelper.transform.forward * StrengthOfCurrent*.1f);
    }
}

The transform of the helper object has the correct forward to push the player along the path of the stream.

do I need the KinematicCharacterController for this to work?
anyone know of an asset on the store that can do this?
Control a character just with left right arrows and the character follows a path, even going aroung bends. You can also jump along this path but cannot leave it.