You can write your topic however you want, but you need to answer these questions:
Hello, I am wondering how I can make a part move away from another part based on the way the parent is facing.
What is the issue? Include screenshots / videos if possible!
My issue is that my test script is not working. I think I am doing velocity wrong.
wait(2)
local PART = script.Parent.Parent
local brick = script.Parent
brick.Position = PART.Position
brick.Anchored = false
brick.Veloctiy = Vector3.new(0, PART.CFrame.lookVector * (50), 0) --???
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried messing around with CFrame, asking friends, looking at other threads, etc but I can’t seem to get the last line to work. I have another solution to making this work but I want the part to move away from the parent based on where the part is facing. Not in any direction like so:
well the current problem with your script would be Part.Cframe.LookVector * 50 as that would be a Vector3 I believe
now one solution to your problem would be
wait(2)
local part = script.Parent
local brick = script.Parent.Parent
-- this will be used to make sure your facing the part you want to avoid
local g = Instance.new("BodyGyro")
g.CFrame = CFrame.new(part.Position,brick.position)
g.MaxTorque = Vector3.new(500000000,500000000,500000000)
g.Parent = part
local speed = 50
wait(2)
---- body gyro I only call here in case the "brick" part moved.
g.CFrame = CFrame.new(part.Position,brick.Position)
part.Velocity = (part.CFrame + part.CFrame.LookVector * -speed).Position <-- this will make it go backward
edit actually what i just did with velocity would be used for bodyposition which would make it
wait(2)
local part = script.Parent
local brick = script.Parent.Parent
-- this will be used to make sure your facing the part you want to avoid
local g = Instance.new("BodyGyro")
g.CFrame = CFrame.new(part.Position,brick.position)
g.MaxTorque = Vector3.new(500000000,500000000,500000000)
g.Parent = part
local b = Instance.new("BodyPosition")
b.Position = part.Position
b.MaxForce = Vector3.new(500000000,500000000,500000000)
b.Parent = part
local speed = 50
wait(2)
---- body gyro I only call here in case the "brick" part moved.
g.CFrame = CFrame.new(part.Position,brick.Position)
b.Position = (part.CFrame + part.CFrame.LookVector * -speed).Position <-- this will make it go backward
but I can only seem to get it to move if I put it in a loop. While in the original line, it is just ‘thrown’ away from the part so it is seemingly flying through the air by itself without the need of a loop or anything to keep it moving. Is it possible to do the same thing without the use of bodyMovers and loops?
you cold also remove the gyro right after it adjusts the parts orientation
wait(2)
local part = script.Parent
local brick = script.Parent.Parent
-- this will be used to make sure your facing the part you want to avoid
local g = Instance.new("BodyGyro")
g.CFrame = CFrame.new(part.Position,brick.position)
g.MaxTorque = Vector3.new(500000000,500000000,500000000)
g.Parent = part
g:Destroy()
local speed = 50
wait(2)
part.Velocity = part.CFrame.LookVector * -speed + Vector3.new(math.random(-20,20), 0, math.random(-80,-50))
if this would work idk as I don’t have time to test it
local power = 20
local height = 2
local part = script.Parent
local brick = script.Parent.Parent
part.CFrame = CFrame.new(part.Position,brick.Position)
part.ClickDetector.MouseClick:Connect(function()
local directionVector = (part.Position - part.CFrame.LookVector * 1)+Vector3.new(0,height,0).unit
local velocity = directionVector * -power
part.Velocity = velocity
end)
watch the power though because it will make that height of 2 become a height of 40 or more and you’ll lose track of it as it launches out of the atmosphere
local power = 100
local height = 2
local distance = 5
local part = script.Parent
local brick = script.Parent.Parent
part.CFrame = CFrame.new(part.Position,brick.Position)
part.ClickDetector.MouseClick:Connect(function()
local directionVector = (part.Position - part.CFrame.LookVector * distance).unit
local velocity = directionVector * -power
part.Velocity = velocity + Vector3.new(0,height,0)
end)
also I added a clickdetector into part so I could activate it