Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

why does my moving platform not stay in its trajectory ?

Hello,

I created a moving platform using "BodyPosition and BodyGyro" it works perfectly as I wanted it to, however once the orientation of the model i changes it still works but a slight shift this product without any explanation.

Here is the model without orientation: https://gyazo.com/c341faf0bb52bb996ded9bb91d2dffa0

The trajectory of the platform is straight.

Here is the model once oriented differently: https://gyazo.com/305b1a7d8d51d4a9b4c0c9d3bb13bf42

The trajectory of the platform does not remain straight she's slightly drifted.

Here is the script used, which is placed in the model:

local model = script.Parent
local platform = model.Platform
local start = model.Start
local finish = model.Finish
local bodyPosition = platform.BodyPosition

platform.BodyGyro.CFrame = platform.CFrame

while true do
	bodyPosition.position = start.Position
	wait(2)
	bodyPosition.position = finish.Position
	wait(2)
end

and oddly if I place the orientation of the model on: 0, 45, 0 it works the trajectory remains quite straight, but not if I put: 0, 60, 0 for example. Anyone have any idea what's going on?

Thank you !

1 answer

You'd wanna do something like this:

local tweenService = game:GetService('TweenService')

local Model = script.Parent
local Platform = Model.Platform -- it is ideal that this part is anchored, it will move regardless

local Start = Model.Start
local Finish = Model.Finish

local tweenInfo = TweenInfo.new(
	1, -- how long should it take to reach it's destination?
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0, -- how many times should it repeat?
	false, -- should it repeat?
	0, -- delay
)

local startProperties = {
	CFrame = Start.CFrame -- moving it to the start cframe
}
local finishProperties = {
	CFrame = Finish.CFrame -- moving it to the finish cframe
}

local finishTween = tweenService:Create(Platform, tweenInfo, finishProperties)
local startTween = tweenService:Create(Platform, tweenInfo, startProperties) 

while true do
	finishTween:Play()
	wait(2)
	startTween:Play()
	wait(2)
end -- while true do end

7 comments

0

i am beginner to script, i use this one with help roblox youtube tutorial, can you give me an example or something? thank you

0

I've edited my answer, it will continue to tween back and forth (as you wanted to) without the rotation issue!

0

Thank you so much for help me, but there is a script error: "Workspace.MovingPlatform.Script:16: Expected identifier when parsing expression, got ')' - Studio - Script:16 "

0

Ah, remove the comma from the 0 at the end of the TweenInfo. From 0, to 0

0

Thank you ! It works but the problem is that because of this, the character does not move with the platform and the movement is no longer as fluid as with the bodyposition: /

0

Okay, how about use BodyPosition, but use CFrame.Angles() as a way to constantly set the part rotation in order to prevent it from twisting? Like so: BodyGyro.CFrame = CFrame.Angles(XAngleInRadians,YAngleInradians,ZAngleInRadians)

0

oh ok , how to integrate it into the script?

This discussion is preserved as it was. New answers, comments, and votes are closed.