How to make a car move in roblox studio

Help and Feedback Scripting Support

So I’m Working on a game and I want a car to come out of a tunnel and drive to the other tunnel
– and it just goes straight btw to the other side–

So I want to make a car that drives from point B to Point A * note is a one way street *

My grammar is bad since I did this in a rush

2 Likes

You can build a looping lerp function pretty easily. The idea behind it would be you take the current time, take the modulus based on the duration of this loop, and feed that modulus value into the lerp. Here’s an example:

local RunService = game:GetService("RunService") local car = some.instance -- for the purposes of this post, it is assumed to be a Model local loopDuration = 123 -- some number of seconds for the loop duration to take place local pointA = Vector3.new(1, 2, 3) -- up to you local pointB = Vector3.new(4, 5, 6) -- up to you function calculateLerpedCFrame(t, pointA, pointB) local displacement = pointB - pointA if displacement.Magnitude == 0 then -- pointA and pointB are identical return pointA end local direction = displacement.Unit local lerpedPosition = pointA + (displacement * t) local lerpedCFrame = CFrame.new(lerpedPosition, lerpedPosition + direction) return lerpedCFrame end function calculateLoopedLerpValue(timestamp, duration) return timestamp % duration end function onStepped() local currentDateTime = DateTime.now() local timestamp = currentDateTime.UnixTimestampMillis / 1000 -- put it into seconds with rough millisecond accuracy local lerpParameter = calculateLoopedLerpValue(timestamp, loopDuration) local carCFrame = calculateLerpedCFrame(lerpParameter, pointA, pointB) car:SetPrimaryPartCFrame(carCFrame) end RunService.Stepped:Connect(onStepped) -- or use one of the new run service signals
  • disclaimer - I wrote this all just in Chrome so I may have missed this up a bit.

1 Like

I have no idea what it means since I’m trash at script.

I meant this "new run service signals’

1 Like

Pretty much the script that Post 2 sent is basically Lerping the Car

Lerping pretty much takes an end position (Provided that you already have a start position to get a direction result) and a range between 0 & 1, it’ll return back the Lerped CFrame I believe

Although I would try this, it would be confusing to other members

Another way you can try is by assigning a BodyVelocity object to the Car itself for it to move from Point A to Point B that way, then detect when the Car ends by detecting a Touched event for Point B

2 Likes

how would you make it so its not a loop, and only lerps in a random amount of time?
for example, this script:

local TweenService = game:GetService("TweenService") local PlaneLobby = script.Parent local tweenInfo = TweenInfo.new( 23.448, -- Time Enum.EasingStyle.Linear, -- EasingStyle Enum.EasingDirection.InOut, -- EasingDirection 0, -- RepeatCount (when less than zero the tween will loop indefinitely) true, -- Reverses (tween will reverse once reaching it's goal) 0 -- DelayTime ) local tween = TweenService:Create(PlaneLobby, tweenInfo, {Position = Vector3.new(-345.317, 58.508, -260.597)}) while true do local n = math.random(30, 120) wait(n) print(n) tween:Play() PlaneLobby["Plane Sound"]:Play() end

it waits a random amount of time, then goes to its vector 3 position

Help and Feedback Scripting Support

Hello! My name is Sandessat, I know some things of LUA (Comments to Coroutines), and to prove my knowdeledge: I want to make a car, but I dont know how to start doing this with scripts.

I have the base and wheels done, if you need more information about them, tell me!

BASE: The body of the car, it is a mesh made from blender.
WHEELS: It is a mesh made from blender.

None of them are welded or anything, they’re just added normaly as a mesh in ROBLOX Studio.

1 Like

So the tutorial series I’ve linked is the same for other cars and trucks types besides drifters. This series should help you out, best of luck!

Edit: You can add or remove steps from the video.

5 Likes

Here are some more resources I found:
The basic roblox tutorial car on the dev forum article using Constraints method, the drive script is worth checking out:

https://developer.roblox.com/en-us/articles/building-carkit-1

Control mechanism I found, it’s a better solution to the while true do loop(can get laggy since it always runs) of the Roblox default tutorial:

How to make a car move in roblox studio
Vehicle Input Controller Module Community Resources

Heya fellow developers! I was just updating my Input module for my car game and thought someone else might find it useful, so here you go! local m = {} -- functions local inputs = {} -- input states local controls = {} -- keybinds inputs.Throttle = 0; -- User input determining the power sent to the wheels inputs.Steer = 0; -- User input determining the angle at which the wheels should be turned. inputs.Clutch = 0; -- A mediator between the engine/throttle and the wheels inputs.Ha…

This thread has some pretty interesting formulas to apply for suspension:

How to make a car move in roblox studio
Car Suspension (Scripted) Scripting Support

Jailbreak Cars. I’ve been hearing a lot about them in the past few months and I’m really keen to get stuck into the mechanics of their suspension rig. After doing my research, I have found out from numerous sources, that the rig uses Body Gyros & Body Thrusts in combination with ray-casting at each corner of the vehicle to acquire the force to push down on each wheel. This makes sense. The only part that doesn’t make sense is how this would relate to the servo movement of the wheels individuall…

This thread also has a list of possible ways to script a car:

How to make a car move in roblox studio
Is anyone able to help me understand vehicles? Scripting Support

If youre looking for cross compatible support like on my game test, you should not use vehicle seat input at all. Some of the controls are terrible, specifically for mobile and console. The joystick, for example, controls both steer and throttle. The triggers also control throttle but the input is not analog. It is mostly better to map them yourself once you got basic input handling down. You can just use values for brake and throttle based on things like the fingers position or the triggers pre…

Overall, look through them and decide which one is best for your purposes. Good luck applying and further improving your LUA skills!

7 Likes

30 min

Uh oh! Your browser doesn't appear to support embedded videos! Here is a direct link to the video instead.

×1
How to make a car move in roblox studio
×1
How to make a car move in roblox studio
×1
How to make a car move in roblox studio
Wheel WheelMount Base DriveScript
How to make a car move in roblox studio
How to make a car move in roblox studio
How to make a car move in roblox studio
How to make a car move in roblox studio
How to make a car move in roblox studio

Uh oh! Your browser doesn't appear to support embedded videos! Here is a direct link to the video instead.

How to make a car move in roblox studio

How to make a car move in roblox studio

Cylinder

AngularActuatorType Motor
AngularLimitsEnabled
How to make a car move in roblox studio
InclinationAngle 90

How to make a car move in roblox studio

How to make a car move in roblox studio

Slider

ActuatorType None
LimitsEnabled
How to make a car move in roblox studio

How to make a car move in roblox studio

How to make a car move in roblox studio

Limits

LowerLimit -1
Restitution 0
UpperLimit 1

How to make a car move in roblox studio

Uh oh! Your browser doesn't appear to support embedded videos! Here is a direct link to the video instead.

How to make a car move in roblox studio

How to make a car move in roblox studio

Spring

Damping 400
FreeLength 2.2
LimitsEnabled
How to make a car move in roblox studio
MaxForce inf
Stiffness 30000

Uh oh! Your browser doesn't appear to support embedded videos! Here is a direct link to the video instead.

How to make a car move in roblox studio

Behavior

Anchored
How to make a car move in roblox studio
Archivable
How to make a car move in roblox studio
CanCollide
How to make a car move in roblox studio
CollisionGroupId 0
Locked
How to make a car move in roblox studio
Massless
How to make a car move in roblox studio

How to make a car move in roblox studio

Uh oh! Your browser doesn't appear to support embedded videos! Here is a direct link to the video instead.

How to make a car move in roblox studio

Behavior

Anchored
How to make a car move in roblox studio
Archivable
How to make a car move in roblox studio
CanCollide
How to make a car move in roblox studio
CollisionGroupId 0
Locked
How to make a car move in roblox studio
Massless
How to make a car move in roblox studio

Uh oh! Your browser doesn't appear to support embedded videos! Here is a direct link to the video instead.

Duplicate Wheels

1. Move Wheel Against Base

Uh oh! Your browser doesn't appear to support embedded videos! Here is a direct link to the video instead.

2. Duplicate/Move Back Wheel

Uh oh! Your browser doesn't appear to support embedded videos! Here is a direct link to the video instead.

3. Duplicate/Move Front Wheels

Uh oh! Your browser doesn't appear to support embedded videos! Here is a direct link to the video instead.

How to make a car move in roblox studio

How to make a car move in roblox studio
How to make a car move in roblox studio

Uh oh! Your browser doesn't appear to support embedded videos! Here is a direct link to the video instead.

How to make a car move in roblox studio

Parts

Part0 WheelMount
Part1 Base


How to make a car move in roblox studio

Uh oh! Your browser doesn't appear to support embedded videos! Here is a direct link to the video instead.

2. Set Hinge Properties (Both Sides)

A. Select Both Hinges

Uh oh! Your browser doesn't appear to support embedded videos! Here is a direct link to the video instead.

How to make a car move in roblox studio

Hinge

ActuatorType Servo
LimitsEnabled
How to make a car move in roblox studio

How to make a car move in roblox studio

Servo

AngularSpeed 5
ServoMaxTorque 100000
TargetAngle 0

Uh oh! Your browser doesn't appear to support embedded videos! Here is a direct link to the video instead.

Filter workspace (Ctrl+Shift+X)

How to make a car move in roblox studio

How to make a car move in roblox studio

Workspace

How to make a car move in roblox studio

Camera

How to make a car move in roblox studio

Terrain

How to make a car move in roblox studio

How to make a car move in roblox studio

Obstacles

How to make a car move in roblox studio

DriveScript

How to make a car move in roblox studio

How to make a car move in roblox studio

WheelBL

How to make a car move in roblox studio

How to make a car move in roblox studio

WheelBR

How to make a car move in roblox studio

How to make a car move in roblox studio

WheelFL

How to make a car move in roblox studio

How to make a car move in roblox studio

WheelFR

How to make a car move in roblox studio

How to make a car move in roblox studio

Base

How to make a car move in roblox studio

Baseplate

How to make a car move in roblox studio
How to make a car move in roblox studio

Uh oh! Your browser doesn't appear to support embedded videos! Here is a direct link to the video instead.

How to make a car move in roblox studio

Tags: