How to make something dependent on the mouse position?

Does anyone here know how to detect something dependent on the mouse pos because I’m trying to make a violin bow move from the X Pos for moving the bow from left to right, the Y Pos for the orientation of the bow playing for different strings, and it has nothing to do with the Z position.

==============================================================
Infos, elaborations, and considerations:

  • An animatable unanchored violin moved by motor 6d, which is a viewmodel, parented into the camera in workspace as a localscript.
    image No Animation
    image Idle Animation

  • I can send you a place file for you if you want me to for helping purposes.

  • I’m very BAD at cframes and editing motor 6ds so please don’t help me without explaination.

Image:

You can take the value of Mouse.Hit.p from the client via a RemoteEvent and use that to calculate the position of the bow.

1 Like

Only problem is I don’t know how to calculate the position, and i don’t think I can move the right arm or the violin bow’s cframe because it’s moved by animation from a motor 6d weld.

You actually can move the right arm by editing the right arms C0 property because of the CFrame math.

Part0.CFrame * Motor6D.C0 * Motor6D.Transform = Part1.CFrame * Motor6D.C1

Animations edit the transform property so you still can freely modify the C0 in order to change the part1 CFrame which represents the Part1 of the Motor6D which is the right arm in the case.

For further simplicity we can set the Motor6D C1 to CFrame.new() to get rid of it to make the equation simpler.

Part0.CFrame * Motor6D.C0 * Motor6D.Transform = Part1.CFrame *CFrame.new()--CFrame.new() is empty or does nothing therefore....
Part0.CFrame * Motor6D.C0 * Motor6D.Transform = Part1.CFrame

This to conclude to modify the part1 CFrame we can modify the .C0 property.

But how do we modify the C0 property to be dependent on mouse position?

Well you can use CFrame math like @Ty_Scripts taking a property of mouse like mouse position and putting it inside CFrame.new(mouse position) while also having to inverse the Part0 of the CFrame to do it in order to position the right arm in the mouse position like so using this formula to position the Part1 at the mouse position.

motor.C0 = motor.Part0.CFrame:inverse() * CFrame.new(mousePosition)
--Positions the part1 at mouse position

Another example is that you could multiply the C0, with a CFrame.new of the mouse delta using UserInputService | Roblox Creator Documentation

local mouseDelta = --use the service
motor.C0 = motor.C0 *CFrame.new(mouseDelta.X,mouseDelta.Y,0)

In order to mimic arm movement.

Unfortunately, I’m pretty busy and theres there’s way more CFrame math operations we can do. I recommend trying it out or maybe looking at different CFrame projects like an fps framework which also does C0 manipulation to do the view models to get an idea of how to manipulate it. Hope this helps.

3 Likes

You could use Mouse.X which is the mouse’s position on the screen and use a bindable renderstepped function to get the time and movement from last position Mouse | Roblox Creator Documentation
And RunService | Roblox Creator Documentation (edit) Mouse.X also has a Mouse.Y just like u need with no Z axis

1 Like

Those two formulas don’t work for me.

First formula, this makes the bow outside of the right arm instead.

motor.C0 = motor.Part0.CFrame:inverse() * CFrame.new(mousePosition)

The second formula, i don’t think it works.

local mouseDelta = uis:GetMouseDelta()
motor.C0 = motor.C0 *CFrame.new(mouseDelta.X,mouseDelta.Y,0)