How to get the orientation (Vector3) between 2 parts?

NOTE: I’m trying to get an orientation between 2 Vector3 points, but I’m not trying to make 1 part look at another, so for my instance, CFrame.lookat wouldn’t work.

Trying to make a shockwave effect for landmines that has a larger range than the kill range. I need to get the orientation between partA (Humanoid Root) and partB (epicenter of Shockwave) and then apply a force on the Humanoid Root opposite of the given orientation, of course with multipliers.

TL;DR: How to get Vector3 orientation between 2 Parts

You can just subtract the two Vector3 values to get the orientation between them. You can use the Unit property of Vector3 to get a unit vector, which you can apply the multiplier to.

Here’s a little example script I made to demonstrate your situation:

local awayParts = workspace.BlastAwayParts
local blastPart = script.Parent

local multiplier = 50

task.wait(5) -- Wait for video convenience

for index, part in pairs (awayParts:GetChildren()) do -- Loop through every BlastAwayPart
	local orientation = part.Position - blastPart.Position -- Orientation by subtracting final-initial Vector3s
	local unit = orientation.Unit -- Unitize it (magnitude of 1)
	local blastOrientation = multiplier*unit -- Apply multiplier
	
	part:ApplyImpulse(blastOrientation) --Apply impulse
end

Here’s a video of the script in action:

3 Likes

Why won’t LookAt work?

vector = CFrame.LookAt(humanoidRootPart, target).LookVector * -forceMagnitude
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.