# Transform a world vector3 to a object's rotation

So if I had a vector of <0, 0, 1> lets say, and then I had an object rotated by 90 degrees on the X axis, how would I find the original vector relative to that object.

Edit: to make it more obvious what I want, I’ve attached a pictures of 2 vectors. the first is of a world vector, and then the second is of the object vector. Given the objects CFrame, how would I calculate the second vector.

1 Like

Couldnt you use object.CFrame:ToObjectSpace(CFrame.new(world_vector)) * CFrame.fromOrientation(orientation)?

Or am i understanding the question wrong?

1 Like

I’m not 100% sure of what precisely you’re asking, but if it’s what I think then what you’re looking for is the CFrame function `vectorToObjectSpace`.

If you’re using ‘vector’ to mean a position vector, then you’ll want CFrame’s `pointToObjectSpace` instead.

5 Likes
``````local vec = Vector3.new(0,0,1)
local relativeCFrame = CFrame.Angles(0, math.rad(90), 0)
local adjustedVector = (relativeCFrame * CFrame.new(vec)).p
``````
1 Like

So I’m trying to make an air vent system that’ll push the player away. Right now my code just pushes them around in a circle.

``````local function CalculateThrustForce(c0, c1, pushDirection, maxDistance, maxForce)
local distance = (c1.p - c0.p).magnitude
local float = (maxDistance - distance) / maxDistance
local force = pushDirection * maxForce * float

end

local thrust = Instance.new("BodyThrust")
thrust.Name = "WaterVentThrust"
thrust.Force = CalculateThrustForce(character.HumanoidRootPart.CFrame, partCFrame, pushDirection, maxDistance, maxForce) -- luacheck: ignore
thrust.Location = character.HumanoidRootPart.CFrame.p
thrust.Parent = character.HumanoidRootPart

spawn(function()
while player.Character and character:FindFirstChild("HumanoidRootPart") and character.HumanoidRootPart:FindFirstChild("WaterVentVelocity") do -- luacheck: ignore
velocity.Force = CalculateThrustForce(character.HumanoidRootPart.CFrame, partCFrame, pushDirection, maxDistance, maxForce) -- luacheck: ignore
wait()
end
end)
``````

BodyThrust objects continue to apply force in a relative direction to the part that they are parented to. This means, that the force applied to the character will change it’s direction as the character gets turned or flipped.
You could try using a BodyForce object instead, as the direction for the force will stay relative to the world instead of relative to the part.

2 Likes

That was the issue, thank you!

1 Like