For a throwable item, should I use raycasting, or something else?

I’m throwing to make a throwable weapon, similar to Murder Mystery’s throwable knife. I’m not sure where to start.

What should I use? I’ve tried the mouse position thing, but it’s really buggy and often goes in the wrong direction.

I also don’t really know how raycasts work, if that is a better way to do it, so it’d help a lot if anyone could show me some tutorials.

Thanks!

1 Like

You could make a Tween using Tween Service and then create a event to check if the part was touched.

1 Like

So I would just make it tween forwards, from where the mouse is pointing?

Also, is that a good way to do it?

I think it is a good way to do it.
You need to make a tween to the Mouse.Hit.Position

Do you know why it isn’t working using BodyVelocity and such? It’s making the item go in the wrong direction occasionally.

You could use the Part.AssemblyLinearVelocity property, example:
Part.AssemblyLinearVelocity = CFrame.lookAt(Part.Position, Mouse.Hit.Position) * 100
This is going to make the velocity of the part be 100 and make the part look at the Mouse.Hit.Position

1 Like

I’ve run into a slight problem - I’m making the knife move on a server script, how would I get the player’s mouse then?

You can create a Local Script and when the mouse button is pressed fire the server with a remote event (and you include the param Mouse.Hit.Position in the remove event)

I’m getting this error:

Players.RipPBB_TUD.Backpack.ThrowingObject.ServerSide:27: invalid argument #2 (Vector3 expected, got number)

Line 27:

kclone.AssemblyLinearVelocity = CFrame.lookAt(kclone.Position, mouseHit) * 100

In the local script, I’m sending this:

script.Parent:WaitForChild("ThrowEvent"):FireServer(m.Hit.Position)

What changes should I make?

Part.AssemblyLinearVelocity = CFrame.lookAt(Part.Position, Mouse.Hit.Position) * Vector3.new(100,0,0)
Try using this :arrow_up:

2 Likes

It’s giving me the error “Position is not a valid member of Vector3”

I’m not sure what I’m doing wrong here.

Error line:

kclone.AssemblyLinearVelocity = CFrame.lookAt(kclone.Position, mouseHit.Position) * Vector3.new(100,0,0)

LocalScript:

script.Parent:WaitForChild("ThrowEvent"):FireServer(m.Hit.Position)

In the server script you don’t need to add .Position
The variable itself is the position

1 Like

Seems like you’re already getting pretty far with DanilochRBX, but you could have looked up a question like this on Google.

I found a video on making a “throwable knife like mm2” in nearly 10 seconds:

That’s the tutorial I used. I followed it, but the end result was a buggy knife that didn’t always follow the mouse.

1 Like

The object just falls onto the floor, instead of where my mouse is.

So I tried this code in my game, and It seems to work:

script.Parent.OnServerEvent:Connect(function(player,pos)
	workspace.Part.CFrame = CFrame.lookAt(workspace.Part.Position, pos)
	workspace.Part.AssemblyLinearVelocity = workspace.Part.CFrame.LookVector * 100
end)

Here’s a video, if you need it:
https://gyazo.com/12f71bb50d7acf05c8a62b580fb9a674

I’m having multiple issues:
The mesh isn’t showing, and the knife doesn’t follow the player’s mouse.

Using your script, it’s giving me an error.

Players.RipPBB_TUD.Backpack.ThrowingObject.ServerSide:26: invalid argument #2 to 'lookAt' (Vector3 expected, got CFrame)

Line 26:

kclone.CFrame = CFrame.lookAt(kclone.Position, mouseHit)

The mouseHit variable represents Mouse.Hit.Position right?

1 Like

Whoops, forgot that. The knife is now dropping to the floor still.

https://gyazo.com/619e93d3688f179a723d0d72801dac04

Is the knife anchored? It can’t be anchored to LinearVelocity work.