I am trying to make a automatic moving helicopter this is my script
while wait() do
script.Parent:SetPrimaryPartCFrame(script.Parent:GetPrimaryPartCFrame()*CFrame.new(0,0,0-1))
end
The problem is its not smooth
I am trying to make a automatic moving helicopter this is my script
while wait() do
script.Parent:SetPrimaryPartCFrame(script.Parent:GetPrimaryPartCFrame()*CFrame.new(0,0,0-1))
end
The problem is its not smooth
I tried but the problem is if anything hits the model it changes the orientation or the position of the model
Unfortunately since you are incrementing it’s position manually you are going to be limited by the server’s physics rate.
If you want to avoid relying on the wait
function you could bind it’s movement to a runservice event:
local vehicle = script.Parent
local speed = 30 -- studs per second
game:GetService("RunService").Heartbeat:Connect(function(dt) -- 'dt' is the time in seconds since the last physics frame, we can use it to more accurately calculate the vehicle's position WRT time.
vehicle:SetPrimaryPartCFrame(vehicle.PrimaryPart.CFrame * CFrame.new(0, 0, -1 * speed * dt))
end)
omg its sooo much smoother now thanks so much!!
sorry but it looks smooth when i run it but it looks weird when i play it:
That’s because the movement is being dictated by the server and in an online game it has to replicate to all clients, and the small delays can cause that staggering. Running the CFrame code on the client would fix it, but if you’re planning to have players ride in the vehicle I might actually recommend using bodymovers as mentioned before.
Follow up on this tutorial:
Basically you weld every part of the model to the main part and tween that instead.
In addition to that, you can set each parts network owner to thee client by using:
Part:SetNetworkOwner(playerhere)
https://developer.roblox.com/en-us/api-reference/function/BasePart/SetNetworkOwner
I made a moving helicopter like this. I used TweenService.
Here how it works:
This strategy allows the server to dictate the movement of the helicopter without using any physics. All physics are on the client, so this avoids a lot of networking lag. Here’s a video of what it looks like:
Edit: Forgot to mention why use AlignPosition. Making the actual helicopter’s movement based on physics on the client smooths out a lot of the choppiness. When you tween something on the server, it will not appear smooth to clients. The AlignPosition constraint fills in the gaps so that the helicopter can still have smooth movement.
The problem with body mover is players can stop the model from moving by pushing or something
Iam just a basic builder and I don’t know much about scripting but thanks!
You should use TweenSercice
local tweenService = game:GetService("TweenService")
localHeliMoveTween = tweenService:Create(Helicopter.Basepart),TweenInfo.new(3,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut),{Position = TargetPart.Position})
localHeliRotateTween = tweenService:Create(Helicopter.Basepart),TweenInfo.new(3,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut),{Rotation = TargetPart.Rotation})
HeliMoveTween:Play()
HeliRotateTween:Play()
you can’t use models with tween service, only parts, bc to use models, you HAVE to tween their CFrames, not Positions - which is borderline to impossible; you can though, implement your own routine which will lerp CFrames, but it will NOT be as smooth as HingeConstraints
This is partly true, but the solution for Tweening
models is easily achieved. The key is to Tween
a value between 0 and 1 over the required timescale, using whichever Easing
style or direction you desire. Bind a Changed:Connect
function to the value and store the inputs from the connection in a table. Once the Tween
completes you now have a table containing a percentage change between start (0) and finish (1). This range is easily iterated, essentially allowing you to use Roblox’s interpolation algorithms and apply them to do anything you want, to any object you choose.
Example:
this.wmv (4.8 MB)
this can be achieved with this utility function, BUT i repeat, the motion is noticeably laggy compared to actual physics simulation, such as Constraints or VectorForce
local tweenSvc = game:GetService('TweenService')
local TW_FPS = 60
local function tween_cframe(m, twi, val)
local co = coroutine.create(function()
local init_cf = m:GetPivot()
local alpha = nil
for i=0, twi.Time, 1/module.TW_FPS do
alpha = tweenSvc:GetValue(i/twi.Time, twi.EasingStyle, twi.EasingDirection)
m:PivotTo(init_cf:Lerp(val, alpha))
task.wait()
end
end)
coroutine.resume(co)
end
tween_cframe(model, TweenInfo.new(5), model:GetPivot() + Vector3.new(10, 0, 0))