VectorForce to move an elevator up or down

I have an elevator to move players up or down. It used BodyForce to go up and down, however that was causing this issue: https://gyazo.com/07bac8e41ef19d993f36dd706be0b503

I switched to VectorForce but I can’t get it to work quite right. Below is my code for moving the Elevator up when the button is pressed. How can I fix it?

This is the intended behaviour: https://gyazo.com/b1289eb033d9aef3bb506ce836b7d230 (Using BodyForce)

However with the below code the platform just doesn’t move.

local Speed = 1;
local MovingUp = false;
local Shaft = script.Parent.Shaft;

function MoveUp(Player)
	if not MovingUp and Player then
		MovingUp=true
		Shaft.Main.Anchored = false

		local partMass = Shaft.Main:GetMass()
		local yForce = (Speed * partMass) + (workspace.Gravity * partMass)
		Shaft.Main.VectorForce.Force = Vector3.new(0, yForce, 0)
		
		repeat wait() until Shaft.Main.Position.Y >= script.Parent.PosUp.Position.Y or not MovingUp
		Shaft.Main.Anchored = MovingUp and true or false
		Shaft.Main.VectorForce.Force = MovingUp and Vector3.new(0,0,0) or Vector3.new(0, -yForce, 0)
		if MovingUp then
			Shaft.Main.VectorForce.Force = Vector3.new(0,0,0)
		end
	end
end;

I’d rather use a PrismaticConstraint for an elevator.

6 Likes

I hope this isn’t too bad of a suggestion, but have you tried part tweening?

Tweening does not mesh well with physics. It doesn’t use physics to move the elevator, so you will run into issues like players clipping through the elevator. A prismatic with its actuator type set to motor or Servo is the right way to approach this.

3 Likes

True, I hadn’t considered that, I recently played with part tweening myself and thought it MIGHT help. Whoops.

Part tweening doesn’t use physics to move I’d imagine, only updating a parts CFrame or Vector3.

With tweening you are updating c-frame. Physics doesn’t update by manually setting properties. You have to use physics objects like constraints or body Movers.

I have used CFramed elevators before:
Advantages:
-Extremely reliable. No physics bugs causing it to bug out, no players getting stuck, no speed changes, less likely to be broken by a Roblox update.
-Lower server cpu load
-The elevator itself is perfectly smooth due to being moved locally in my system.

Disadvantages:
-other players will appear to clip through it when it moves (Not sure if this still happens with physics ones)
-even with a velocity applied to its base parts, it sometimes causes the character to stutter.

Notes:

  • physics-based elevators will be smooth as well because they are interpolated
  • performance for physics-based elevators is Trivial as well. If you’re basing Your Design around this, you are doing something wrong
  • physics-based elevators are extremely reliable if you put them in a collision group that can only collide with players

Elevators controlled with C frame should never, ever be used unless you have some extremely weird use case in which physics-based elevators don’t work. Otherwise, it is just a symptom of developers unnecessarily liking to implement everything manually.

I have to agree with @EchoReaper. I’ve done both methods. CFraming is not going to work well. It will look nice, but will not operate appropriately due to physics.

Using physical movers will be the best method all the time

1 Like

I can’t figure out how to use PrismaticConstraints in my scenario, the page linked above isn’t of much help in terms of explaining how to actually use it. How do I move the part? Changing the velocity in APS doesn’t do anything

PrismaticConstraintExample.rbxl (14.0 KB)

Run the game, set PrismaticConstraint.TargetPosition to 10, and then back to 0 after a few seconds to get a general idea of how it works. The direction the part moves will be the opposite of the yellow arrow on the world attachment.

10 Likes