Unexpected results with BasePart.Velocity applied on a Character

I am currently trying to get the player to go to a point based by his mouse and a Ray using BasePart.Velocity.

The thing is that it only works on normal parts that I use to have a visual of what is happening. When I set the velocity of the HumanoidRootPart, the player has difficulty in having the velocity in question and even when I jump, the player does not go completely on the target in question.

It’s crazy I do not understand. At first I tried to weld the HumanoidRootPart to the part that was working in question. All this on the client of course, and it did not work and the part began to travel like the player, very difficultly.

I first thought it was because I was on the client, so I tried on the server and it’s the same result.

The physics on Roblox are starting to get a little upset. When I use a BodyVelocity, it’s hard because the physics of the parts are sleeping, there is not really any proper constraint to have a constant velocity and even when I use BasePart.Velocity I have problems? Any ideas on what could be the problem in this case and how to fix it?

Here’s a reproduction of the place in question : Repro.rbxl (18,7 Ko)

local function jumpToWall()
character.Humanoid.Jump = true
local cachedPosition = mouse.Hit.p
local rayToMouse = Ray.new(game.Workspace.CurrentCamera.CFrame.Position,cachedPosition)
local part,pos,norm = game.Workspace:FindPartOnRay(rayToMouse,character)
local magnitude = pos and (character.PrimaryPart.Position-pos).magnitude
local endEffector = pos and (pos-character.PrimaryPart.Position)
if part and magnitude <= maxMagnitude then
	local g = Vector3.new(0,-game.Workspace.Gravity,0)
	local x0 = character.HumanoidRootPart.CFrame * Vector3.new(0,0,0)
	local v0 = (pos-x0-0.5*g*t*t)/t
	
	local p = Instance.new("Part",game.Workspace)
	p.Size = Vector3.new(3,3,3)
	p.CanCollide = false
	p.CFrame = character.PrimaryPart.CFrame
	p.Velocity = v0
	
	local p2 = Instance.new("Part",game.Workspace)
	p2.Anchored = true
	p2.Size = Vector3.new(1,1,1)
	p2.CanCollide = false
	p2.Position = pos
	p2.Color = Color3.fromRGB(255,0,0)
	p2.Material = Enum.Material.Neon
	
	local weld = Instance.new("Weld")
	weld.Part0 = p
	weld.Part1 = character.PrimaryPart
	weld.Parent = weld.Part0
	
	character.PrimaryPart.Velocity = character.PrimaryPart.Velocity + v0
end
end
1 Like

First of all, I would like to point out to not use the parent parameter for Instance.new(). Also I don’t know if this will help because that problem is a little odd, but have to tried multiplying the velocity by v0 instead of adding?

1 Like

I’m using Parent as a second argument considering that what I’m doing is something I’ve just started and that is risky and something that will not go further. So I do not care if tomorrow it becomes deprecated or whatever. In the second place, the proposition you have just made me is quite disturbing. It seems to me that in no way multiplying the velocity will change anything. I expect people who propose solutions to have a certain base on vectors as such.

I was thinking your problem was something to do with the speed. Usually, you would get the mouse.Target.LookVector and multiply It by the speed. Guess not. What confuses me is why it works with regular parts, but doesn’t with the HumanoidRootPart.

1 Like

The problem with characters is that a lot of their behavior (like standing up, moving around and jumping) needs physics of its own. While the character appears without any bodymovers of any sort in the explorer, its actually embedded with some necessary forces which I believe come with Humanoid.

Now, when you apply a custom velocity on top of the embedded physics, there is interference which is what creates the undesirable results. ROBLOX exposes a humanoid state (called Physics) to allow players to apply completely custom physics to their characters. Of course in this state, your character becomes uncontrollable (in the sense that it stops responding to, say the W, A, S, D keys) and starts to topple just like any other part in workspace.

What you can do is switch to Physics humanoid state for as long as you want the character to be thrown around and then switch back.

8 Likes

Working well as you can see

Thanks and also thank you @Alphexus for your propositions

1 Like