Hey all, I’m making a train that is controlled using the throttle from a VehicleSeat that is then mirorred into a VectorForce.
Here’s the model!
And here’s the hierarchy.
And this is the script…
local RunService = game:GetService("RunService")
local VehicleSeat = script.Parent:WaitForChild("VehicleSeat")
local Velocity = VehicleSeat:WaitForChild("VectorForce")
local accel = 0.05
local speed = 0
RunService.Heartbeat:Connect(function()
local throttle = VehicleSeat.Throttle * accel
speed = math.clamp(speed + throttle, -20, 80)
print(speed)
Velocity.Force = VehicleSeat.CFrame.LookVector * speed
print(VehicleSeat.CFrame.LookVector * speed)
end)
The issue is that although the force changes, the train does not move. As in, the force property changes and everything but nothing moves. I’ve checked the gliders and they are not messing with anything - they’re just not… moving.
hello!
The VectorForce needs an attachment for work, and in your hierarchy the VehicleSeat doesn’t have an attachment; probably this is the problem. If afther this there is still no movement, probably you need to check the welds, that could be impeding the movement.
Well Force is way different then velocity. You need way more force like maybe 10,000 so multiply the speed by a high number top get results. Force depends on the mass and friction.
“A VectorForce will apply its force on the Parent of its Constraint.Attachment0, but the location where the force is applied is determined by the VectorForce.ApplyAtCenterOfMass property”.
"Direction of force
The direction of the force is determined by the Vector3 defined by force, but it will also be affected by the VectorForce.RelativeTo property.
By default, VectorForce.RelativeTo is set to Enum.Enum.ActuatorRelativeTo.Attachment0, meaning the force will be applied in the space local to the attachment. Remember that when visualizing an attachment, the yellow arrow shows the direction of positive X, and the orange bar shows the direction of positive Y. If the part the attachment is connected to rotates, the force will change direction to make sure it is still in the context of the attachment.
RelativeTo can also be set to Enum.Enum.ActuatorRelativeTo.Attachment1. In this case, the force will be applied in the space local to Constraint.Attachment1, regardless of the orientation of Attachment0 or its connected part. If Attachment1 rotates, then the force will change to stay oriented correctly.
Lastly, RelativeTo can also be set to Enum.Enum.ActuatorRelativeTo.World. In this mode, the force is applied in world coordinates, regardless of the orientation of Attachment0 or its part."
(VectorForce | Roblox Creator Documentation)
This is from the roblox API, referring to VectorForce. Doing my own tests I discovered that the attachment is neccesary, mainly to know which part will receive the force. RelativeTo modifies the direction of the vector, but not the part to apply the force.
RelativeTo only modifies the direction to the vector; if you already have that attachment in the attachment0 property, isn’t necessary modify the RelativeTo property.
for check if it’s up or down, you can write this code:
--vehicleSeat is the variable of the VehicleSeat
VehicleSeat:GetPropertyChangedSignal("Throttle"):Connect(function()
--1 when the key W has pressed
if vehicleSeat.Throttle == 1 then
-- up
elseif vehicleSeat.Throttle == -1 then
--down
end
end)
And yes, the throttle property is modifiable, you can do that