Trying To Make Force Align With Part Orientation

BodyVelocity.MaxForce = part.CFrame:VectorToObjectSpace(Vector3.new(0,((workspace.Gravity)*GetModelMass(plr)*(math.pow(2,math.tan(MovementPower*.4999*math.pi))))))

BodyVelocity.Velocity = part.CFrame:VectorToObjectSpace(Vector3.new(0,MovementSpeed))

Im basically just trying to make a force go relative to the orientation of the part.

For example, if I want to move it up, then I turn the part 90 degrees along the x axis. Now it should act positive along the z axis.
It doesn’t work for all rotations, why?

Heres the full script I’m currently using

local Direction = "Horizontal"
local MovementSpeed = 30 -- Speed at which it moves (positive is forwards/up)
local NormalSpeed = 80 -- Speed at which to show the normal scrolling  texture
local IdleSpeed = 30 -- Speed at which to show force field
local MovementPower = 0.75 -- scale from -1 to 1 based on how much control the player has to move against the force. 0 means equal force, 1 means player cannot move against, -1 means force doesn't effect player
														  -- Recommended to set at .75 I definitely would not set at one
	CreateVerticalTexture(ForcefieldImage,IdleTransparencyHorizontal)
	part.Touched:Connect(function(partTouched)
		if partTouched.Parent and game.Players:FindFirstChild(partTouched.Parent.Name) then
			local plr = partTouched.Parent
			if not PlayersTouching[plr] then
				PlayersTouching[plr] = partTouched
				local RootPart = plr.LowerTorso
				local connect1 
				connect1 = part.TouchEnded:Connect(function(part)
					if part == PlayersTouching[plr] then
						connect1:Disconnect()
						
						PlayersTouching[plr] = nil
						if RootPart and RootPart:FindFirstChild("SpeedyBlockVelocity") then
							RootPart.SpeedyBlockVelocity:Destroy()
						end
					end
				end)
				
				local BodyVelocity = Instance.new("BodyVelocity", RootPart)
				BodyVelocity.Name = "SpeedyBlockVelocity"
				BodyVelocity.MaxForce = part.CFrame:VectorToWorldSpace(Vector3.new(((plr.Humanoid.WalkSpeed)*GetModelMass(plr)*(math.pow(2,math.tan(MovementPower*.4999*math.pi)))),((workspace.Gravity)*GetModelMass(plr)*(math.pow(2,math.tan(MovementPower*.4999*math.pi)))),((plr.Humanoid.WalkSpeed)*GetModelMass(plr)*(math.pow(2,math.tan(MovementPower*.4999*math.pi))))))
				local TargetRelativeVelocity = part.CFrame:VectorToWorldSpace(Vector3.new(MovementSpeed))
				while RS.Stepped:Wait() do
					if plr and BodyVelocity and plr.Humanoid and plr.Humanoid.Health>0 then
						BodyVelocity.Velocity = TargetRelativeVelocity
					else
						if BodyVelocity then BodyVelocity:Destroy() break end
					end
				end
			end
		end
	end)```
1 Like

Also, for some reason, moving the part around its major axis changes the force’s direction. I don’t know why.

1 Like

You want to turn an object-space vector (e.g. “to part’s right”) into a world-space vector, because BodyVelocity expects Velocity to be a world-space vector.

BodyVelocity.Velocity = part.CFrame:VectorToWorldSpace(Vector3.new(MovementSpeed, 0, 0))

Can you explain what you need this for?

1 Like

You can simply make the force relative to the lookvector, rightvector, and whatnot to the part:

BodyVelocity.Velocity = Object.CFrame.LookVector * Amplitude
2 Likes

I tried doing this, but it still doesn’t go in the correct direction away from the part, it should be going up.
Changes around the major axis which should not affect its UpVector still cause changes in the velocity.

Making it relative to the upvector just makes the person always go upwards which isn’t what I want either.

Don’t you want BodyThrust in this case?

Won’t effect the current problem but maybe.

Up vector is local to the part, so if the part was rotated, upvector would change too.

I should mention that the force is a velocity relative to another object (object a) that is acting on this object (object b) lets say I want to maintain a velocity relative to object a (Vector3.new(0,10,0)) and object a is rotated 90 degrees around the z axis. That should turn into Vector3.new(10,0,0) and act upon object b.

But I want to be able to apply a relative velocity. not a magnitude applied to the direction.