Greetings.
I have encountered an issue in my endeavors in learning code, I have spoke to multiple people and have asked around, except I am frequently ignored or spoken over. Finally a new member and maybe Ill have luck seeking my answer here.
I am working on a train chassis that is GUI linked to be controlled via GUI as said before. My main and number 1 issue is the look vector being too slow to change. I have been told to use render stepped or heartbeat, I have looked over the developer resources and what roblox has to offer for understanding but still see little to know understanding over such.
My issue is I am using body velocity to propel the train forward by its look vector and would like to to rotate freely and only posses the force itself. I was told to use body force but it offers little of what I need. My thing is the LookVector will change too slow for the turns causing a tilt to happen for the delayed time.
Would there be a way to have the look vector to consistently change upon its direction of travel instead of the wait() delay itself? I have been researching this for the longest of time and have found no answer, even asking multiple people and out sourcing. This is my biggest issue, the missing piece to the puzzle. Any ideas of what I could use or do for this? I dont have any source code. In fact, I went through at least 23 different renovations, revamps, and rewrites for solutions and nothing has worked for me so far. Hoping I can find my answer here after all.
1 Like
Generally, you should avoid using wait()
like that (here’s why)
That’s probably the best solution. I’ll explain what Heartbeat
does. Heartbeat
is an event, like Touched
and Changed
. Unlike those events, which fire only when something is changed/touched, Heartbeat
fires every frame. Because it fires every frame, it is faster then doing wait()
(which is usually equivalent to wait(1/30)
)
Alright, Could you provide me an example in which I could use that for Body Velocity’s look vector? I want to also minimize lag as well. I just need the script to just constantly check it because its the key to which direction in which it travel. If I am correct there are ways to do that, its just, the reasoning of “How”
--Camera is used, but it could be any object similiar to Camera
local Camera = workspace.CurrentCamera
game:GetService("RunService").Heartbeat:Connect(function()
local LookVector = Camera.CFrame.LookVector
BodyVelocity.Velocity = LookVector
end)
However, if you can fully control your vector, then you wouldn’t even need Heartbeat, you could just have an update function instead, like this:
local Vector = Vector3.new(1, 0, 0)
function UpdateVector(NewVector)
Vector = NewVector.Unit
BodyVelocity.Velocity = Vector
end
‘’'lua
local SpeedForce = game.Workspace.Train1.Part.BodyVelocity
local SpeedOne = script.Parent
SpeedOne.MouseButton1Click:Connect(function()
game:GetService(“RunService”).Heartbeat:Connect(function()
local DOT = SpeedForce.Parent.CFrame.LookVector
SpeedForce.Velocity = DOT*-10
end)
end)
didnt work for me apparently unless I did it wrong