Hi!
Lately I have been trying to get a part to move in the direction its heading, using things like taking two positions and orienting it so that it’s ends are connected with the positions, and taking its velocity and trying to turn it into some rotation value, but I wasn’t able to. Any ideas on how to do this? I feel like I have seen other games that have made this but idk. It is a simple part, its size is 0.5, 0.5, 9 and I nearly got it to work, using this code, but it was too chaotic and got launched into nowhere:
local part = script.Parent
while true do
local pos1 = part.Position
task.wait(.1)
local pos2 = part.Position
-- Set the position of the part
part.Position = (pos1 + pos2) / 2
-- Set the orientation of the part
part.CFrame = CFrame.lookAt(part.Position, pos2)
end
If you are, you can just add .AssemblyLinearVelocity to get a predicted position.
Code:
local part = script.Parent
while task.wait() do
--//Check if the part's speed is over 5 studs a second (if it's not, we will experience glitches when setting the CFrame)
if part.AssemblyLinearVelocity.Magnitude > 5 then
local currentPos = part.Position
local predictedPos = currentPos + part.AssemblyLinearVelocity
part.CFrame = CFrame.lookAt(currentPos, predictedPos)
end
end
Tried, and that is not what I want to accomplish. I want to use the roblox physics and then orient it based on something like position changes or velocity.
here is a video showing what happened. And the part just goes flying after going to a resting point. But it does get closer to the desired affect. It points in the direction it is going in which is nice.
part.CFrame *= CFrame.new(0, 0, 3) -- Change this to whatever axis the part is facing.
If you need help figuring out what the proper axis is, just click “Edit Pivot” and see what arrows are accurately displaying the direction the part is facing. Red arrow = X axis, Green arrow = Y axis, and Blue arrow = Z axis.
local part = script.Parent
while task.wait() do
-- Check if the part's speed is over 10 studs a second
-- If it's not, don't set the CFrame because glitches will happen
if part.AssemblyLinearVelocity.Magnitude > 10 then
local currentPos = part.Position
local predictedPos = currentPos + part.AssemblyLinearVelocity
part.CFrame = CFrame.lookAt(currentPos, predictedPos)
end
end
I have actually been messing around with it, and I have set it to 30, which is the best amount I was able to find because 25 was still too bouncy and 35 just stopped doing it too soon but 30 was the best. I still think that it could use some improvement though to do something with the bouncing.
So, I think that I should mark yours as the solution and I will keep working on it to improve it. Adding the thing to make it not as bouncy worked pretty well, and I will go off of that.