Getting Input Of Seated Player

I want to make a seat, similar to that of pilot seat from Build a Boat for Treasure, where the player can change its orientation with WASD keys, but I don’t have exact idea of how I would make that. Currently I have 2 main questions:

  1. How to “Lock” the seat’s rotation, so it stays the same until player changes it. - I have no idea at all on how to do that.
  2. How to control the seat. - I suppose, I could use Humanoid.Seated event to connect it to a function, and then in that function get the input of the player. But Im unsure if it is the best way.

However, I don’t have proper experience with seats, and I don’t even know if I should use vehicle seat or regular seat.

Any suggestions?

you could use AngularVelocity to lock the rotation and to rotate it, you can also use the steer and throttle properties of a vehicleSeat to control the rotation

1 Like

Are these properties only available for vehicle seat, or regular seat too?

only vehicle seat has throttle and steer, a regular seat does not

1 Like

Thank you, for some reason did not see at first, that you mentioned these properties are properties of Vehicle seat.

I tried to use the Occupant property of the seat to check if somebody is inside, and then use context action service to control it. But it didn’t quite work.

local contextActionService = game:GetService("ContextActionService")

local seat = script.Parent

local function Steer(input, inputState)
	if input == Enum.KeyCode.W and inputState == Enum.UserInputState.Begin then
		seat.AngularVelocity.AngularVelocity = Vector3.new(-1, 0, 0)
	elseif input == Enum.KeyCode.W and inputState == Enum.UserInputState.End then
		seat.AngularVelocity.AngularVelocity = Vector3.new(0, 0, 0)
	end
end

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if seat.Occupant ~= nil then
		contextActionService:BindAction("Steering", Steer, false, Enum.KeyCode.W)
	elseif seat.Occupant == nil then
		contextActionService:UnbindAction("Steering")
	end
end)

is the maxTorque of the angular velocity set to a high number?

I think its like 20000, isn’t it default value?

  • Use Vehicle Seats
  • Instead of context action service, you can also use the Throttle and Steer PropertyChanged Signal
  • Connect the Signal to a function when a player sits, store that connection in a variable
  • When a player leaves Disconnect that Signal

  • Check if the Steer function is being triggered using print statements
  • Also check the way the whole assembly is rigged, could give insights to why the AngularVelocity didn’t work

I’m not quite understanding how the throttle and steer work on vehicle seat. Are they being changed when player presses the WASD keys? Like, throttle for W and S, and steer for A and D? I tried looking documentation but sadly its one of those cases where there are no examples for codes or anything.

*I also think the angular velocity works fine, its just that I had its AngularVelocity property set to (0, 0, 0). If I were to change it to something like (0, -1, 0) the seat would rotate the way I want it to. Its only the problem with code itself.

The documentation says the following about ThrottleFloat and SteerFloat:

ThrottleFloat:

The direction of movement, tied to the keys W and S. Must be an integer 1 (forward) 0 (null) or -1 (reverse). Will refresh back to 0 unless constantly set.

SteerFloat:

The direction of movement, tied to the keys A and D. Must be one of 1 (right), 0 (straight), or -1 (left). Will refresh back to 0 unless constantly set.

So, ThrottleFloat will be 1 when they’re trying to move forwards, and -1 when they’re trying to move backwards, and 0 if they’re trying to do neither.
Same deal with SteerFloat, 1 means turning right, and -1 means turning left, and 0 means straight. You can take ThrottleFloat and multiply it with some speed, say 30, and apply that to a LinearVelocity constraint or a VectorForce constraint, and do something similar with SteerFloat and an AngularVelocity or AlignOrientation contstraint.

Here’s a place file that I threw together:
BoatTest.rbxl (63.8 KB)

1 Like

That explains a lot. But I was also wondering if I could add an additional key. So for example, if I press the E key while in seat, something is being changed or activated. What would I use in this case?

I also stumbled in another issue. I want the seat to rotate on horizontal axis relative to world, but on the vertical axis it should rotate relative to itself. I could not make it in one angular velocity, so I made 2 separate angular velocities, but result is quite weird.

Solved the issue with 2 angular velocities. Decided to use just one, and make an additional check for RelativeTo property, where as if you try to steer, it will check if RelativeTo is World, and if its not, it is changed to world. Same with Throttle but reversed. This does not allow to Steer and Throttle at the same time but it works. Still, I don’t know how to add an additional key to seat.