LinearVelocity doesn't work when RelativeTo is set to "World"

Hello, first post on the dev forum, I’m making a parkour game with some similar mechanics to Flood Escape 2. One of those mechanics being sliding. Here is the module script right now:

function abilitytable.slide(Character, Track: AnimationTrack) -- Character model and animation to be played, passed along from requiring local script
	
	game.ReplicatedStorage.RemoteEvents.Slide.Slide:FireServer() -- This is just for updating the stamina bar and communication across the client
	
	local hrp = Character:WaitForChild("HumanoidRootPart")
	
	local lv = Instance.new("LinearVelocity", hrp)
	local Attach0 = Instance.new("Attachment", hrp)
	lv.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
	lv.Attachment0 = Attach0
	lv.ForceLimitMode = Enum.ForceLimitMode.PerAxis
	lv.MaxAxesForce = Vector3.new(100000, 0, 100000)
	lv.VectorVelocity = Vector3.new(0, 0, -20)
	
	script.Slide2.PlaybackSpeed = math.random(95, 105) / 100 -- Playback speed of sound effect is randomized
	script.Slide2:Play()
	Track:Play(0.1, nil, 2)
	
	repeat task.wait() until (UIS:IsKeyDown(Enum.KeyCode.E) == false) -- Wait until the E key is released to stop sliding
		or (Character:WaitForChild("Humanoid").FloorMaterial == Enum.Material.Air) -- Or if the character is in the air then stop sliding
		or (Character:WaitForChild("Humanoid").FloorMaterial == nil)
	lv:Destroy()
	Track:Stop()
	Attach0:Destroy()
	
end

I’m not that good at scripting so there is definitely some room for improvement here and dealing with physics, CFrames, etc. just isn’t my strong suit.

Anyway, with how the mechanic is currently implemented, the player can still turn while sliding. From the moment they hold E, the direction of the linear velocity must lock so that the player cannot turn. That isn’t seemingly possible with it being relative to an attachment.

For comparison, here is the expected behavior [Top] and the current behavior [Bottom]. Observe how with the expected behavior, turning with shiftlock while sliding does not change the direction the player slides in.

(The fumbling sound at the end of the clip is from in-game)


I have tried using the look vector of the humanoidrootpart and changing the rotation of the attachment very rapidly and offsets, all that stuff, but it does not seem possible without making the direction of the linear velocity in global space. Issue is, the linear velocity just stops working altogether when relative to the world. So hopefully someone can help me out. Cheers.

1 Like

In case you are wondering why the sliding is so short in the top video, it’s because in Flood Escape 2 sliding has a max time, which I have yet to implement into my system

What do you mean by making the linear velocity relative to global space? You already have it sliding in a locked direction so what more more do you want?

The direction that the linear velocity is pushing the player in is relative to where the player is facing. I do not want that.

what do you want it to do then lol?

Watch the videos in the post

eeeeeeee

the top video just looks exact the same except max slide time and the player just rotates character? nothing else

Observe closer. In the top video, the direction you slide in doesn’t change if you use shiftlock. In the bottom video, changing your direction with shiftlock changes the direction you slide in. It’s a little hard to see because the max time is very short

don’t freak out but that’s how shiftlock works, it locks ur player to camera

I ain’t talking about the direction the player faces. I’m talking about the direction the player slides in. those are two different things

and im telling you the top video the characters slides to facing direction

It doesn’t.

eeeeeeeeeeeeeeeeeeee

Oh yea i see it only makes the player slide in the direction they were facing before they began sliding.

When you’re talking about changing the direction, are the directions like front, back, right, and left directions?

you could check if localplayer is on shiftlock, then use a d keys to change direction manually

  1. capture lookvector
  2. add delay like 0.1s
  3. slide

I need the linear velocity to work with RelativeTo set to “World”, if that’s simpler.

and that’s a problem to my solution how?

The devforum is for helping to solve problems not argue. The OP already said what you’re talking about is not what they’re looking for

and you are forgetting hes asking for help because he doesn’t know how to do it
just because he tells that’s not what hes looking for doesn’t mean that it’s not a solution :slight_smile:

Capturing the lookvector is what I want to do but it’s completely pointless to do so because the linearvelocity doesn’t move the player at all while relative to the world