Roblox spacecraft

I just need some guidance getting started,
How would I begin creating the spacecraft. Do I use oop? How do I store the variables in a module? How should be scripts be organized. please help

1 Like

I would recommend creating it with OOP. Think of it like an engine class and a driver class. The stats and variables would be put inside the spacecraft’s engine, which is inheriting from the engine class.

If you don’t know how to script, then I would go study scripting some more.

If you do know how to script and want some basic structure read the following.

local class = {}
class.interface = {}
class.functions = {}
class.metatable = {__index = class.functions}

function class.interface.new(x: number, y: number)
	local self = setmetatable({}, class.metatable)

	self.x = x
	self.y = y
	return self
end
type class = typeof(class.interface.new(table.unpack(...)))

function class.functions.addXY(self: class)
	return self.x + self.y
end


return class.interface

You can use this code, it will give you a good start for oop. Add in more members into class.functions for more functions. Don’t touch class.interface

If you want to read and learn about how it works I recommend these articles:

dont use this format, its just a basic one to explain sum stuff

if you need any more clarification just ask :slight_smile:

2 Likes

I understand oop and have already got to work! I’ve run into this one bug though and I’m so lost.

local SpaceCraftModle = require(game:GetService("ReplicatedStorage").Spacecraft)

local CraftA = SpaceCraftModle.new("Model1", 1500, 15, 5)
CraftA:Electronics()

thats the server
and module:

local Spacecraft = {}
Spacecraft.__index = Spacecraft

function Spacecraft.new(Model, Health, Manuverabilty, Speed)
    local self = setmetatable({}, Spacecraft)
    self.Health = Health
    self.Manuverability = Manuverabilty
    self.Speed = Speed
    
    
    self.Electronics = false
    self.Engine = false
    
    
    self.Model = game:WaitForChild("ReplicatedStorage").Ships:FindFirstChild(Model):Clone()
    self.Model.Parent = game.Workspace
    
    return self
end

function Spacecraft:Electronics(state)
    if state == true then
        print("on")
    else
        print("off")
    end
end

return Spacecraft```

"Attempt to call a boolean Value"

ah you changed up Spacecraft:Electronics(state) from what it should be.
welp you got rid of good idiom.I dunno what is wrong with your code, not enough detail. Need to know where being errored

1 Like

I found the issue,
How would I go about making the craft move?

I would probably use some sort of physics mover(if you want collisions etc)
I would use AlignPosition and AlignOrientation

I would create my spacecraft class to hold the members of the model, info on how fast etc.

Then I would have a function to move the spacecraft.
Every frame I would change the AlignPosition and AlignOrientation goals to reflect the changes made.
I would just have to customize what values would be made the new goals(you could do this with button presses or smth)

Break each part of the spaceship into chunks, then put it all together in a class.
Don’t start writing the class first. (the reason for this is convenience of testing, its easier to see where stuff fails and debug the fails)

the goals would be the properties and they would be adjusted using math and an addition of the direction of the button press. what do you mean by a function to move the craft? could you write a small snippet please so I can just visualize.

Sure

Class:ChangeGoalOffset()
--connect to user input service changes
--If there is a change then move the .position and .CFrame aspects of your alignPosition and orientation.
--in the next physics frame then add these offset values.
end

This would just be updating some constant you are using every physics frame to change AlignOrientation and AlignPosition

1 Like

Alright Ill give it a shot.
Do you have discord so i Can ask you more questions?

Naw, you can just message me here.

It’s no problemo for me to stay on roblox platform.

Read up on physics movers, and make a few things with them before trying out your spaceship.
Just some simple moving blocks would work and then experiment with changing the different goal properties.

The best way to answer questions is to just read up and experiment.

1 Like

Ive found success using the align position and adding a vector 3 to the position propriety on the align position and that causes the part to move. Do you recommend doing this?

Absolutely, thats what I was referring to.

Spaceships have perpetual motion, so just moving it constantly works fine.


local sittingConnection = nil
game.ReplicatedStorage.Spacecraft:WaitForChild("SpawnShip").OnClientEvent:Connect(function(Craft)
	PlayerAircraft = Craft
	
	 sittingConnection = localplayer.Character.Humanoid.Seated:Connect(function(IsSitting, SeatPart)
		if IsSitting == true then
			if SeatPart.Name == "pilotSeat" then
				PlayerAircraft:ChangeGoalOffset()
			end			
		end
	end)
	
	
end)

game.ReplicatedStorage.Spacecraft:WaitForChild("destroyShip").OnClientEvent:Connect(function(Craft)
	sittingConnection:Disconnect()
end)

this is what ive come up with is this the most efficient way of handling controls?
do you have any other ideas or reccomdentations?

for

Class:ChangeGoalOffset()
--connect to user input service changes
--If there is a change then move the .position and .CFrame aspects of your alignPosition and orientation.
--in the next physics frame then add these offset values.
end

this does it have to be called on the server or client?

You need to have the client tell your server about the change to the goal.(dont let them send the position, just the input).

Then you do the 2nd two comments in your ChangeGoalOffset() function.
Your setup looks perfectly fine, and is a very good example of oop. :+1:

1 Like

Hey, I didn’t know enough to continue this, but now I believe I do.

I want to recreate this system using physics movers, which instaves should I use to get a dynamic feel to the craft where there is a learning curve?