How do I make a viewmodel drop down when the player jumps

uso un runservice para el viewmodel y el evento Humanoid.Jumping cuando salte pero que calculo uso para bajar el viewmodel rapido y subirlo?

any tutorial or documentation MESIRVE

Try this

local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
local viewportFrame = script.Parent -- assuming this script is a child of the viewport frame
local viewportModel = viewportFrame:FindFirstChild("YourModelName") -- replace with your model's name

-- Set up BodyVelocity
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Velocity = Vector3.new(0, -50, 0) -- change the values to suit your needs

-- Set up Tween
local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut) -- change the values to suit your needs
local goal = {} 
goal.Position = viewportModel.Position -- this will be the original position of the model
local tween = TweenService:Create(viewportModel, tweenInfo, goal)

-- Connect to Jump event
humanoid.Jumping:Connect(function()
	viewportModel.Parent = workspace -- move the model to the workspace so it can be affected by physics
	bodyVelocity.Parent = viewportModel -- add the BodyVelocity to the model
	wait(1) -- wait for the model to drop
	bodyVelocity:Destroy() -- remove the BodyVelocity
	tween:Play() -- tween the model back to its original position
	tween.Completed:Wait() -- wait for the tween to finish
	viewportModel.Parent = viewportFrame -- move the model back into the viewport frame
end)

Perdona si cometo faltas de ortografía, el español no es mi lengua materna.

Asumiendo que estás usando RunService, puedes tener un valor separado que alterna entre cierto o falsa cuando el jugador empieza y para de saltar. Aquí hay un script de ejemplo que se me ocurrió:

local RS = game:GetService("RunService")

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")

local isJumping = false

local function OnJumpStart()
	isJumping = true
	
	--// Viewmodel drops down.
end

local function OnJumpEnd()
	isJumping = false
	
	--// Viewmodel returns to original position.
end

RS.Heartbeat:Connect(function()
	if hum.Jumping then
		if not isJumping then --// If we haven't registered the jump already:
			OnJumpStart()
		end
	else
		if isJumping then --// If we have a registered jump, remove it:
			OnJumpEnd()
		end
	end
end)

¡Espero que esto ayude! :slight_smile:

1 Like

I use a runservice.RenderStepped the value of when it jumps is ready, what I need to know is guidance on how it would make it jump, Math.sin,Lerp()? which one would give me guidance on how it would make it jump.
@SilentGalaxZy body velocity is obsolete and it is not optimized at all with a viewmodel, the viewmodel is positioned with runservice and has certain conditionals that check if the player walks or runs or is still, I want to know what method I should use to lower the viewmodel when it jumps.

I don’t speak spanish my speak is frances

local RunService = game:GetService("RunService")
local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
local viewportFrame = script.Parent -- assuming this script is a child of the viewport frame
local viewportModel = viewportFrame:FindFirstChild("YourModelName") -- replace with your model's name

local startHeight = viewportModel.Position.Y
local endHeight = startHeight - 5 -- the lower position of the model during the jump
local lerpSpeed = 0.1 -- speed of the lerp, adjust to suit your needs

local function step(deltaTime)
	if humanoid:GetState() == Enum.HumanoidStateType.Jumping then
		-- Lerp the model down while jumping
		local newPos = viewportModel.Position.Y - lerpSpeed
		if newPos < endHeight then newPos = endHeight end -- don't go below endHeight
		viewportModel.Position = Vector3.new(viewportModel.Position.X, newPos, viewportModel.Position.Z)
	elseif viewportModel.Position.Y < startHeight then
		-- Lerp the model back up after jumping
		local newPos = viewportModel.Position.Y + lerpSpeed
		if newPos > startHeight then newPos = startHeight end -- don't go above startHeight
		viewportModel.Position = Vector3.new(viewportModel.Position.X, newPos, viewportModel.Position.Z)
	end
end

RunService.RenderStepped:Connect(step)

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