Path translating help

Need help translating a player on to a path with out translating the player on the direction the player is supposed to freely move on the path

what’s happening is the player translate fine when I move left but doesn’t translate correctly at all when I move right some on please help me this gets called before I translate the player based on his velocity.

 public void FaceAlongPath( )
        {
            var StagePath = Path;
            var StageFolow = StagePath.GetNode<PathFollow3D>("Folow");
            //int dir = Char_Parent.Char_Input.LeftStick.Direction();
            Vector3 localBodyPosition = StagePath.ToLocal(Char_Parent.GlobalPosition);
            Vector3 ClosestPointLocal = StagePath.GlobalPosition + StagePath.Curve.GetClosestPoint(localBodyPosition);
            Vector3 closestPointGlobal = StagePath.ToGlobal(ClosestPointLocal);
            StageFolow.Progress = StagePath.Curve.GetClosestOffset(Char_Parent.GlobalPosition);
            Vector3 Direction = StageFolow.GlobalTransform.Basis.X;
            Vector3 toPath = closestPointGlobal - Char_Parent.GlobalPosition;
            toPath.Y = 0;
            PathRad = Mathf.Atan2(Direction.X, Direction.Z); // these are the radians that rotate the input along the path 
            Basis Cutoff = new(Vector3.Up, PathRad);
            Vector3 freeAxis = Cutoff.X;
            freeAxis.Y = 0;
            freeAxis = freeAxis.Normalized();
            toPath -= freeAxis * freeAxis.Dot(toPath);
            toPath = Util.Vector3.PlaneProject(toPath,Cutoff.X); 
            Char_Parent.GlobalTranslate(toPath);
        }
  1. Define “translate” in this context.
  2. From your code it looks like this is 3D, but it’s good to specify that.
  3. This code is overly complicated. Is there a reason you aren’t just using NavigationRegiond3D and NavigationAgent3D and the look_at() function to accomplish the same thing with many fewer lines of code?

1 when I mean translate I mean keep the player along the path3D
2 my bad bro
3 it’s not about looking at something it’s about making sure the player is on the path and there movement is not disrupted by it that’s why

Umm what’s with all this code? Shouldn’t you be just copying the transforms from the path follow node?

1 Like

I can’t do that I need to translate the player on the path because that will mess with how the player is moving for context I’m making a 2.5D video game

What do you mean by “translate player on the path”? Can you illustrate more clearly what are you trying to do. Maybe post a video/mockup.

this is a top down view btw and I need all this to happen with out dissrupting the players movement

What’s the purpose of PathFollow3D then?

I need the direction in wich the path is facing to move the player towards as well

I don’t get it. Why just not advance the PathFollow3D along the path and copy its transforms.

because the player has physics and can interact with terrain if I just simply copy it’s position then the physics wont work

Then why constrain it to a path? Whichever method you use to constrain it’ll need to override physics. What exactly are you trying to achieve here? Do you have a video mockup or an example from an existing game?

1 Like

I have to go right now lets talk tomorrow ok?


it’s a 2.5D sonic like game is what I’m trying to achive
https://www.youtube.com/watch?v=W9WOYZsEB7g and movement along a path that does this with out effecting the physics

Which aspects of physics shouldn’t be affected? Gravity?

gravity, slope rotation, and just about everything related to velocity being aplied to the player

So based on your screen shot, I’d recommend you just change the gravity using an Area3D to override the gravity vector to keep pointing at the loop. You can either detect the normals of each object and reverse them, or create an Area3D for each. Either way, then you don’t have to do anything but get_gravity() in your player code. You don’t have to worry about velocity, slope rotation, etc.

The example game you posted never alters the gravity direction (in sonic loops fashion). It always seems to be pointing “down”.