# Horse tail problem

How do I make a system where when my horse runs faster the tail goes higher but when you go slower the tail slowly goes lower? I’m stuck with this problem for the past hours

A way you could test this out is by trying to make a car, and then the higher the speed is, move a part accordingly. Then figure out a way to implement this into your horse

But how do I do that? I can’t find anything related to that.

Get the velocity of the horse, this will be a vector pointing at a certain direction.

``````local vel = HumanoidRootPart.Velocity
``````

Normalize the velocity and compare it with the horse HumanoidRootPart’s Look vector to ensure it’s moving forward.

``````local n_vel = vel.Unit -- Returns a normalized vector

local lookvector = HumanoidRootPart.CFrame.LookVector
``````

We must also invert the look vector to compare it to velocity later.

``````lookvector = Vector3.new() - lookvector

local difference = (n_vel - lookvector).magnitude
``````

Difference should be close to 0 if both vectors are pointing in the opposite direction.
Should be close to 2 if the horse is moving forward (both vectors are very similar).

Now calculate the angle for the horse’s tail.

``````local angle = math.deg( difference * 45 )
``````

This angle can now be used in a CFrame to make the tail go up when the horse moves.
Now this is a super simple approach, but you could modify it to take different kinds of speed into account.

This might always make the tail go up 90 degrees no matter how fast you’re moving.
The tail might also go up if you’re moving sideways.

(Also fellow scripters feel free to correct my math if you spot an error.)

I recommend you learn about vectors and directions because they can be really helpful.

Velocity for example is a Vector3 which points at an direction (10,0,0 would be moving 10 studs per second to the right for example).

LookVector is a property of CFrame that also points towards an direction (again 1, 0, 0 would be pointing to the right).
Except LookVector never exceeds 1 stud.

You can picture LookVector as an sphere with an arrow in it that points forward.

Velocity can also be pictured as an sphere with an arrow in it, except the length of the arrow might be longer than 1 stud in the case of moving 10 studs a second.

By comparing the two you can get a difference (normalize to 1 stud by doing `Vector.Unit`).

An alternative method would be converting the Velocity to a object space value so you can use X, Y and Z directly to make the horse tail move and might give better results actually.

1 Like

You should use CFrames and welds/motor6d, you’re literally moving the part itself and it’s not going to stay attached to the horse.

1 Like