Physics Simulator
PhysicsSimulator simulates track-based physics. It is primarily used for coasters, but can also be used for transport rides and drop towers/tracks.
PhysicsSimulator should only be used with PointToPoint type CFrameTracks. Other tracks maybe not behave properly.
Example
local physicsSimulationState = physicsSimulatorV1.SimulationStateBuilder.new()
:withCFrameTrack(TRACK)
:withTrackSectionsData(TRACK_SECTIONS_DATA)
:withCurrentPosition(keyframeRecorder:getLastPosition())
:withModelDirection(MODEL_DIRECTION)
:withClampPositionToTrackLength(true)
:withGravity(GRAVITY)
:withFriction(FRICTION)
:withTimeInterval(TIME_INTERVAL)
:withStopPosition(STOP_POSITION - TWEEN_START_OFFSET, "Stop", false)
:withStopWhenDirectionChanges() -- stop immediately when valleying
:withUpdateType(PhysicsUpdateType.WithPositionOffsets(mainWheelSetOffsets))
:build() -- builds the simulation state
:unwrap()
local physicsRecorder, _simulationStopType = physicsSimulatorV1.simulate(physicsSimulationState, PHYSICS_STATE)
UpdateType
Stopping the Simulation
Simulating returns a SimulationStopType
SimulationStopType
- HasPassedStopPosition
- StoppedByTypeSection
- HasValleyed
- DirectionChanged
- ReachedMaxSimulationTime
StopPositions
Rollbacks
The stopWhenDirectionChanges
flag will stop the simulation when the moveDirection
changes in the PhysicsState
.
You can enable it in the SimulationStateBuilder using :withStopWhenDirectionChanges()
.
When stopped, simulation will return the DirectionChanged type