I am trying to accomplish hockey skating in roblox. I don’t really know where to start with this. I know that I will have a button like “p” to enter “player mode”. This would enable skate-like physics. If you know any could forum posts that would be helpful please reply down below as I can’t find much on it. If you know how I could do this don’t give me the full script, but please lead me in the direction.
For the skating you’re probably going to want to visit these links: Animation | Roblox Creator Documentation and AnimationTrack | Roblox Creator Documentation as well as Animation Editor | Roblox Creator Documentation and Using Animations | Roblox Creator Documentation
The physics of actually playing the game are probably going to be more difficult.
Ima be honest this didn’t help me at all. ofc I would need animations, but this didn’t help me with implementing it into a replacement for roblox’s =.
Ok, but that isn’t stated in your original post and we can’t read your mind to know exactly what you are asking.
Sorry, I’ve never done this exact procedure, but there is a section on how to replace the default animations in the Using Animations | Roblox Creator Documentation link. I’m pretty sure you’d just have to use UserInputService | Roblox Creator Documentation to get the player’s input (‘p’ for example) to enter player mode and then use that input to change the default animations.
Alright, do you know if there is a way I can change the players weight and stuff? As for stopping in hockey takes a few seconds, but in roblox it is instant.
If you are using bodyvelocity then don’t decrease it to 0 instantly.
If you are CFraming it you need to calculate how the speed would reduce.
How are you doing it?
Also, have you tried decreasing the Friction of the ice Part?
I am not calculating it at all, I am wondering how I would do it. Is there a way that roblox has built in for me to modify that kind of stuff?
You could disable the default movements when you want to start skating, give the player a forward velocity, and allow the player to increase/decrease their speed when they use the W/S keys, while making it so they can turn using the A/D keys.
As for “built in” features, I’m not really sure those exist for skating. So you probably need to find another method to achieve this.
Alright, I will look into that. Do you have any articles that you know about that would help me in increase and decreasing speed with velocity?
I’m not the most familiar with it, so the only article I could refer you to is the API documentation on it.
BodyVelocity (roblox.com)
If you use BodyVelocity then as I said don’t decrease it to 0 immediately, causing the player to coast for a while.
If you script the BodyVelocity to increase or decrease depending on player input then that should work.
If they press W you could apply the force (say 10000 for example) fully for good acceleration, but if they release the W key then instead of making the force 0 you could use a loop to decrease it by 1000 every .5 seconds which would get it to 0 in 5 seconds. If they pressed W for a 2 for 2 seconds to start moving forward but changed their mind and pressed S the full force would be applied backwards so it may take a second to go from full forward to full reverse since the 10000 force backward would have to overcome the 10000 force that was shut off when you switched from W to S.
I will try this out, were should I put the body velocity?
Put a script into StarterPlayerScripts | Roblox Creator Documentation so that each player gets it when they spawn.
Have that script insert the BodyVelocity into the player, then you can use it to control the player on the ice.
Alright I will let you guys know how it goes tommorow.
Alright so this is working, but I am having a little bit of an issue getting the player to slowly turn to the left when he presses A.
local function TurnLeft()
local CurrentForce = BodyVelocity.MaxForce
local CurrentNeeded = 5
repeat
wait(.2)
BodyVelocity.Velocity = (player.Character.HumanoidRootPart.CFrame * CFrame.Angles(math.rad(5),math.rad(player.Character.HumanoidRootPart.CFrame.Y),math.rad(player.Character.HumanoidRootPart.CFrame.Z))).LookVector * 40
BodyVelocity.Velocity = -player.Character.HumanoidRootPart.CFrame.RightVector * 3
BodyVelocity.MaxForce += Vector3.new(5000, 0, 0)
until Turning == false
print('Done turning')
end
This is what I have so far, this works as far as getting him to move the left, but now I want his player to face the left, so when he presses W it accelerates him forward to his new position. yes, I already have a system built for him going forward and backward. Just the turning is the hard part.
Above this message. Is a response.
https://gyazo.com/6dcd368d8ea3752065e0d2eb7153ab6d
local function TurnLeft()
local CurrentForce = BodyVelocity.MaxForce
local CurrentNeeded = 5
repeat
wait(.2)
BodyVelocity.Velocity = (player.Character.HumanoidRootPart.CFrame * CFrame.Angles(math.rad(5),math.rad(player.Character.HumanoidRootPart.CFrame.Y),math.rad(player.Character.HumanoidRootPart.CFrame.Z))).LookVector * 40
-- BodyVelocity.Velocity = -player.Character.HumanoidRootPart.CFrame.RightVector * 3
-- BodyVelocity.MaxForce += Vector3.new(5000, 0, 0)
local part = Instance.new("Part", player.Character)
local weld = Instance.new("WeldConstraint", player.Character.HumanoidRootPart)
weld.Part0 = player.Character.HumanoidRootPart
weld.Part1 = part
local thinger = Vector3.new(player.Character.HumanoidRootPart.CFrame.X, player.Character.HumanoidRootPart.CFrame.Y, player.Character.HumanoidRootPart.CFrame.Z) + Vector3.new(10,0,0)
part.CFrame = CFrame.new(thinger)
part.CanCollide = true
part.Anchored = true
part.Parent = workspace
print(part.Position.X, part.Position.Y, part.Position.Z)
player.Character.HumanoidRootPart.CFrame = CFrame.lookAt(player.Character.HumanoidRootPart.Position,Vector3.new(part.Position.X, part.Position.Y, part.Position.Z))
task.wait()
until Turning == false
print('Done turning')
end
Any idea why he just looks forward?
Because you are just using a BodyVelocity.
You need a BodyGyro | Roblox Creator Documentation or an AngularVelocity | Roblox Creator Documentation to turn the player.
Imagine walking along the street and someone pushes you sideways, this would be a BodyVelocity. It doesn’t cause you to spin towards the direction you were pushed. You need a torque (twist) around your vertical axis to cause you to rotate. Check the above links.