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?
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;
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.
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.
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
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
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.