Move object based on VectorForce

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!

image

And here’s the hierarchy.

image

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.

Any help is appreciated! Thanks.

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.

1 Like

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.

Velocity is just a variable here for the vectorforce… it could easily be called anything else. The Force is a property of VectorForce.

And @SoyunPRO5724 you are right but i believe you can also set the RelativeTo to World and then you dont need attachment but i could be wrong.

2 Likes

I know, I’m just saying you need a lot of force for an object to move due to mass and friction. But, you are right.

1 Like

“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.

2 Likes

Thanks for testing and letting us know, this is very helpful and should help the OP with the issue.

2 Likes

heya, where exactly would i put the attachment?

image
image

Also, the welds are simply the gliders WeldConstrainted to the Base

the attachment must be a child of the VehicleSeat, so that with the attachment there you can move the VehicleSeat.

And the welded parts must not have unnecessary welds, as these can are welded to the BasePlate and prevent the vehicle from moving.

They are only welded to the train and nothing else, I’ve checked.

To the other post, so just create an Attachment inside the Vehicle Seat and then set Attachment0 to that and make it relative to Attachment0?

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.

Got it now, thank you so much!

I don’t really want to open a new topic - so could I get your input on another issue of mine?

I’m looking to make a notch based throttle system, and I can’t wrap my head around how I’m going to do this.

All I know is the Notch-Throttle table that I want:
image
Index[1] being the Notch number and Index[2] being the Throttle property.

Would I use UserInputService or instead view the user’s attempted change in throttle and modify it before any change can take place?

I recommend you to use the changes in throttle property; I have already used it using the"GetPropertyChangedSignal" method.

So, in words:

  1. Get the user’s change in Throttle
  2. Check if it’s up or down (how do I check what was done before the change if the event is being run after the change has taken place?)
  3. Match that to the nearest Notch
  4. Change the throttle to the corresponding notch

Correct?

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

1 Like