Part's orientation based off of velocity

I’ve tried many times to replicated this type of effect but i havent been able to get it right
https://i.gyazo.com/c1b06c9f064302527b286eb513cfdd7b.mp4

I’ve tried alot of theese posts for something but i havent been able to achive this.

2 Likes

I’m pretty sure you just gotta set the orientation to the velocity, I could be wrong though. (if that doesn’t work then try using CFrame.LookAt)

All you really need to do is use the lookAt and specify the Velocity as the direction you want to lookAt.

Then you can get your orienation from that.

local Rotation = CFrame.lookAt(Vector3.zero,Part.AssemblyLinearVelocity)

It’s fairly easy to do. You just got to make sure the part is facing the right way by:
Right Clicking>Show Orientation Indicator.

Setting the orientation to the part is the difficult part. I would use the AlignOrientation as it is the easiest.
Just make sure the part has an Attachment

AlignOrientation.Parent = Part
AlignOrientation.Attachment0 = Part.Attachment
AlignOrientation.Mode = Enum.OrientationAlignmentMode.OneAttachment
AlignOrientation.RigidityEnabled = true

Of course you have to set the rotation then every frame

AlignOrientation.CFrame = Rotation
1 Like

The part seems to just dissapear almsot instantaniously

The part will disappear if the velocity is 0 yes.

What causes it to do so? The droplet is supposed to start at 0,0,0 veloctiy.

1 Like

I’ve set the velocity to (0,1,0) and they just float like this, i even tried (0.001,0.001,0.001) but its the same result.
image

I don’t think i specifically pointed out i was trying to re-create the little droplet effect where it turns towards its forwards velocity.

Well, I can give you a reason why is because inside the lookat function there is some trigonometry inside which is calculating the correct way to look at. As the distance between Vector.zero and Velocity is zero the lookAt function will return a NaN NaN NaN vector and object will dissapear. If your cameras gone black this could be the reason why

print(CFrame.lookAt(Vector3.zero,Vector3.zero))

Anyways again just make sure that orientation is correct by going into.
This is a similar implementation using Part Emitter. I thought it’d be a cool exercise for me :nerd_face:

Code
local Randomness = Random.new()

local ZERO_VECTOR3 = Vector3.zero

local CollectionService = game:GetService("CollectionService")
local Debris = game:GetService("Debris")
local RunService = game:GetService("RunService")
local ParticleTemplate = game:GetService("ReplicatedStorage").Particle

-- Functions
local function IsNanCFrame(cframe: CFrame): boolean
	return cframe == cframe	
end


local function Heartbeat(deltaTime)
	local Particles = CollectionService:GetTagged("Particle")
	for _, Particle: BasePart in next, Particles do
		local alignOrientation = Particle:FindFirstChildWhichIsA("AlignOrientation")
		if not alignOrientation then continue end
		local Velocity = Particle.AssemblyLinearVelocity
		if Velocity == ZERO_VECTOR3 then continue end 
		alignOrientation.CFrame = CFrame.lookAt(ZERO_VECTOR3,Velocity)
	end
end

-- Events
RunService.Heartbeat:Connect(Heartbeat)

-- Main Loop
ParticleTemplate:WaitForChild("Trail")
while task.wait(0.3) do
	local cloneParticle: BasePart = ParticleTemplate:Clone()
	cloneParticle.Position = workspace.Baseplate.Attachment.WorldPosition
	cloneParticle.Parent = workspace
	task.delay(task.wait(),function()
		cloneParticle.AssemblyLinearVelocity = Randomness:NextUnitVector() * 10
	end)
	CollectionService:AddTag(cloneParticle,"Particle")
	Debris:AddItem(cloneParticle,10)
end

You just need to do a simple check to see if your velocity is not null first and then apply it like I did.

3 Likes

It doesn’t seem to do anything, Acts the same with and without it. No errors either

Have you made sure that the AlignOrientation is actually able to move the object?

It sounds like the part may be anchored or the constraint isn’t configured correctly/hasn’t been given enough power.

SORRY! it does work i just forgot to apply the AlignOrientation to the attachment.

1 Like

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