As you can see in the video, the sword in my hand doesn’t stay fixed. For example, when I look down, half of the sword disappears from the camera. I want it to be like in Roblox Bed Wars, where the sword’s position on the screen is properly adjusted and doesn’t get messed up when I rotate with the mouse. How can I do this? I’ve tried various methods, but I haven’t been successful.
As you can see in the video, the sword in my hand doesn’t stay fixed. For example, when I look down, half of the sword disappears from the camera. I want it to be like in Roblox Bed Wars, where the sword’s position on the screen is properly adjusted and doesn’t get messed up when I rotate with the mouse. How can I do this? I’ve tried various methods, but I haven’t been successful.
Havent played bedwards but I am going to assume you mean view model items. Think guns in fps games and how they move with your camera.
That video is a rough example of how to do it and should give you some idea of how to proceed with it
Hello, I followed the instructions given, but first, I want the arms to be hidden. Secondly, I want it to work with animations. Thirdly, it only appears on the local side. An external player cannot see the sword we have.
First, you just set the transparency of the ViewModel to be 0
Secondly, you can animate the ViewModel in any way you want and rig up the view model with motor6ds and play it through a local script
Third, it’s supposed to show only on the client, it would look ugly if other people saw it
But there will be a problem. We will see the sword on our own screen, but someone from the outside also needs to see that we have the sword. What I actually want is exactly this. The sword should not distort from any angle and should be visible from the outside as well. The attack animation should also work.
Then just animate the sword on the character and have it shown on their character, that’s what literally any fps game does
I wanted to ask because I don’t know how it’s done technically. Thank you for the replies.
How it’s done is you pivot the sword to your current camera CFrame and multiply by some offset to get it in the right position. Also when zoomed in you hide the sword welded to the arm and you only see the sword being pivoted to ur camera. You do the inverse when zoomed out
So the character and what you see when zoomed in are both different things with each having their own animation
But considering the Bed Wars game in the video, if ViewModel were actually used, wouldn’t the sword be visible on the screen when we switch to the third-person mode? In the third-person view, there is no sword on the screen.
Yes exactly! It would show, so when zoomed out you have to hide the sword.
An easy way to achieve this is to simply offset it behind the camera so you don’t see it anymore
I’m finding it really difficult to do this, so I’m considering giving up and trying a different approach. I haven’t figured out how to do it. I’ve been working on it for 4 days… If I can’t find a guide that shows me step-by-step how to do it, it looks like I won’t be able to do it. I tried many of the things you mentioned. However, somehow, an issue started occurring with the code I wrote. For example, I placed the sword in StarterPack. When I selected the sword from there, I was able to get the ViewModel to appear. Since the StarterPack tool sword would also appear, they would conflict. To prevent this, I tried to make the tool only visible on the server but not on the local side. However, I kept encountering issues. I’m about to give up. Either I always choose the hard way, or what I’m trying to do in this video is actually quite simple…
Share your current code, I’ll see what I can do
local tool = script.Parent
local player = game.Players.LocalPlayer
local replicatedStorage = game:GetService("ReplicatedStorage")
local runService = game:GetService("RunService")
local viewModelName = "ViewModel" -- ViewModel'ın doğru ismi
local viewModel = replicatedStorage:WaitForChild(viewModelName):Clone()
local camera = workspace.CurrentCamera
-- Add the ViewModel to the camera and move it with the camera.
local function updateViewModel()
if camera and viewModel and viewModel.PrimaryPart then
viewModel:SetPrimaryPartCFrame(camera.CFrame)
end
end
tool.Equipped:Connect(function()
print("The sword is selected.")
-- Place the ViewModel on the camera.
viewModel.Parent = camera
viewModel:SetPrimaryPartCFrame(camera.CFrame)
--Make the ViewModel move with the camera.
runService.RenderStepped:Connect(updateViewModel)
-- Hide the Tool for the local player.
tool.Parent = player.Backpack
print("The Tool is hidden locally but displayed on the server.")
end)
tool.Unequipped:Connect(function()
print("The sword has been dropped.")
-- Remove the ViewModel.
viewModel.Parent = nil
print("The ViewModel has been removed from the camera.")
end)
tool.Activated:Connect(function()
print("The attack animation is playing.")
-- Send a request to the server to trigger the attack animation.
game:GetService("ReplicatedStorage"):WaitForChild("SwordSwing"):FireServer()
end)
local tool = script.Parent
local replicatedStorage = game:GetService("ReplicatedStorage")
local swordSwingEvent = replicatedStorage:WaitForChild("SwordSwing")
swordSwingEvent.OnServerEvent:Connect(function(player)
local character = player.Character
if character then
local humanoid = character:FindFirstChildOfClass("Humanoid")
local animation = tool:WaitForChild("SwingAnimation")
if humanoid and animation then
local animationTrack = humanoid:LoadAnimation(animation)
animationTrack:Play()
print("The attack animation was played on the server.")
else
print("Humanoid or animation not found.")
end
else
print("Character not found.")
end
end)
Here are the codes. With explanations! 1. code local script. 2. code server script. I also placed all of them in the sword inside StarterPack.
just move the sword to the camera and offset it
(am i misunderstanding this)
I’m trying to figure out whether I misunderstood or not, but my brain is fried. I need to take a break.
Let’s do it this way. If you wanted to do this, how would you do it step by step?
-
Make a view model . You need to know a bit of rigging for this step . You can use a plugin like this to make this step easier . But basically how the rig would look like is that there would be a Part that is called HumanoidRootPart which is also set to the primary part of the model , and there is an object called handle which is basically your sword model . After your done with adding the parts, use that plugin to add a rig to it so that it is animatable
-
Test your rig . Open animation editor and see if you can move the sword model properly. If you can, then your good to go
-
scripting. The most basic part of this complex step is teleporting the viewmodel to your camera’s CFrame . Since we want the viewmodel to move smoothly, we need to use
RunService.RenderStepped
here is a document on it . Quick explanation on whatRunService.RenderStepped
is is an event that fire every time the Roblox engine is going to render your screen. Ok now you have RenderStepped . The last part is to teleport the model to th camera . Here is a quick sample code
RunService.RenderStepped:Connect(function()
viewmodel:PivotTo(cam.CFrame)
end)