Basically when you are pressing W or moving forward, it will show the player swimming normally, and when you move backwards, it plays an animation of the player swimming backwards. Kinda like in the game pressure, or in subnautica.
You should probably make two different animations for moving backwards and forwards-for example:
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local UIS = game:GetService("UserInputService")
-- Ensure that the character's humanoid contains an "Animator" object
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
-- Create a new "Animation" instance and assign an animation asset ID
local forwardSwimAnimation = Instance.new("Animation")
forwardSwimAnimation.AnimationId = "rbxassetid://yourassetidhere"
local backwardSwimAnimation = Instance.new("Animation")
backwardSwimAnimation.AnimationId = "rbxassetid://yourassetidhere"
-- Load the animation onto the animator
local forwardSwimAnimationTrack = animator:LoadAnimation(forwardSwimAnimation)
local backwardSwimAnimationTrack = animator:LoadAnimation(backwardSwimAnimation)
function inputBegan(input,gameProcessed)
if input.KeyCode == Enum.KeyCode.W then
--forward swimming movement code here
forwardSwimAnimationTrack:Play()
end
if input.KeyCode == Enum.KeyCode.S then
--backward swimming movement code here
backwardSwimAnimationTrack:Play()
end
end
UIS.InputBegan:Connect(inputBegan)
i was thinking of doing the same thing, but i didnt try it cuz i thought maybe it wouldnt work for players on mobile. does this mean the mobile joy stick moving fowards = W on the keyboard?
Keep the code @domo30174 gave you. It supports PC at the very least, which is a good start.
You should look into the documentation of mobile input:
Yeah listen to @Amritss, you should use ContextActionService
Oh then in that case its easier than i thought lol, im pretty familiar with context service since ive used it before. I’ll give it a try.
1 Like
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.