I am trying to create an asteroids-like top-down arcade shooter, but I am having trouble replacing the default avatar with my spaceship model
Here is the code I am using to replace the character model with the spaceship
-- Get a reference to the player's character
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
-- get the default character
local defaultCharacter = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local defaultHumanoid = defaultCharacter:WaitForChild("Humanoid")
local defaultRootPart = defaultCharacter:WaitForChild("HumanoidRootPart")
-- load the spaceship that has the following heirarchy
----Spaceship (model)
------ Humanoid (a humanoid) Rootpart is HumanoidRootPart
------ HumanoidRootPart (a part)
local spaceshipModel = game.ReplicatedStorage.Spaceship:Clone()
local spaceshipHumanoid = spaceshipModel.Humanoid
local spaceshipRootPart = spaceshipModel.HumanoidRootPart
-- Wait for the new character to load
spaceshipModel.Parent = game.Workspace
while not spaceshipModel:IsDescendantOf(game.Workspace) do
wait()
end
spaceshipModel:SetPrimaryPartCFrame(defaultCharacter:GetPrimaryPartCFrame())
-- replace players default humanoid with spaceships
spaceshipRootPart.Parent = defaultCharacter
spaceshipHumanoid.Parent = defaultCharacter
-- Destroy the old character model
defaultRootPart:Destroy()
defaultHumanoid:Destroy()
This code causes the spaceship to appear and the character to disappear briefly, then the spaceship disappears and the default character reappears.
I’m at a loss on how to replace the default avatar in the game. Any help would be appreciated
I could, but I am trying to understand the best way forward. Here are the options I am considering:
I could add limbs or create an entire humanoid rig that I would make invisible. This might be useful as it might allow me to reuse the default player controls.
I anchor the spaceship with my own custom controls. Probably now a wise choice since there will most likely be other unforeseen problems down the road with this.
I reuse the default character limbs and make them invisible. I am unsure on how to do that effectively.
The anchoring stops the jiggle, but the controls don’t work. I’m assuming something is up with the physics configuration that might be addressed with limbs. If not then I will create my own controls
Alright, I was messing around with different configurations and get this… switching from an R15 to an R6 humanoid fixed the jiggle problem, and the default controls work perfectly. Thank you for your help!