2D sprites in a 3D space

hey! i’m creating a game that involves 2d sprites in a 3d plane. kind of like the gif and image below.
0eacec31bece1e83ba5a476a7520282c

i was wondering if anybody had any ideas on the best/easiest/most efficient way to script or go about this? i really just need advice on placing the sprites on the player and having them change for whatever direction they’re facing. thank you!

5 Likes

Probably make the player invisible, attach a BillboardGui to the HumanoidRootPart (or any other part on the character) then get the relative direction between the camera and character ( CameraCFrame:ToObjectSpace(PlayerCFrame) ), then change the sprite based on that.

do you have a really simple way to make the player invisible upon joining? i’ve tried different scripts to no avail. bare with me because i havent scripted in a super long time

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player)
	player.CharacterAppearanceLoaded:Connect(function(character)
		for i,v in pairs(character:GetDescendants()) do
			if v:IsA("BasePart") or v:IsA("MeshPart")then
				v.Transparency = 1
			end
		end
	end)
	player:LoadCharacter()
end)

this code is not well written, and this is a quick and dirty solution but it seems to work fine. i dont recommend using this code permanently though

2 Likes

Wait, huh? Why load the character at the end? Wouldn’t this cause an endless loop?

that only runs when the player joins the game for the first time, it is just in case the character loads before the game sees the characterappearanceloaded event. just to make sure that gets run

Huh… I never actually thought of that. Turns out I’m the one learning here haha, thanks for that

Edit: You should include a case for decals so that the smile turns invisible as well

yeah, it isnt a good solution to the problem though, and there are better ways of doing it. i just wanted to get a reply quickly. this problem only usually happens on bigger games though, that lag more

@TestAccount563344 shared a loop script, but you can also opt for a StarterCharacter.

To create one, simply create a valid rig, name it StarterCharacter, then put it in StarterPlayer.

It is known to cause issues, but this case is simple enough to where it shouldn’t cause some noise.

local Players = game:GetService("Players")

function CharacterAdded(character)
	for i,v in pairs(character:GetDescendants()) do
		if v:IsA("BasePart") or v:IsA("MeshPart")then
			v.Transparency = 1
		end
	end
end

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAppearanceLoaded:Connect(function(Character)
		CharacterAdded(Character,Player)
	end)

	local Character = Player.Character
	
	if Character then -- If the character already exists, the CharacterAdded event probably didn't fire until now.
		CharacterAdded(Character,Player)
	end
end)

in fact, this might be a better code snippet. however i havent tested this

1 Like

didnt even think of that! that is a better solution than using this weird code of mine xD

Accessories and decals can load after this, so if you do use a loop script, I recommend disabling LoadCharacterAppearance in StarterPlayer

or you can just wait for CharacterAppearanceLoaded. but your solution is better anyways and thats what i would recommend OP use

thank you guys very much for all of the scripts and advice!! i tried test account’s scripts and i can’t seem to get them to work however i might be putting them in the incorrect place. i also tested the rig which works but i’m unable to move for whatever reason

The script Test provided should be a server script in ServerScriptService

The reason you can’t move is likely because you forgot to unanchor the HumanoidRootPart of the rig

image
i chose a random rig from the toolbox to test and it does seem to have hrp. still unable to move however. i tested another one with the same issue. i also tried to use the script in sss and it still can’t seem to get it to function.

You’re misunderstanding; the HRP missing is not the problem. If you select and observe the properties of the HRP, it should be anchored, since that’s the default state that rigs are made with. Unanchor it and you should find your movement.

OH, alright, it works! now i have to try and figure out the actual sprite with the message from susdswar3wevrf. thanks again!!

hey! so i’ve been trying this out and the billboardgui thing works great! however i’m having issues when it comes to the actual walking animations according to which way the player is walking. i started another thread for this issue if you want to respond there as there is more context, but here is a dummy script i made which i’m sure has a lot of issues but i can’t figure out what to change. note: my camera is already fixed with another script in order to give it the top down kind of view.

local image = script.Parent.ImageLabel
local anims = image:GetChildren()
local hrp = script.Parent.Parent
local rightw1 = image:GetChildren("RightWalk1")
local rightw2 = image:GetChildren("RightWalk2")

local camera = game.Workspace.CurrentCamera
local humanoid = hrp

if (humanoid.MoveDirection:Dot(camera.CFrame.RightVector) > 0.75) then
	
	image.Image = rightw1
	
	wait(.5)
	
	image.Image = rightw2
	
	wait(.5)
	end

it may be easier to go off of the players movement direction in relation to the camera.
what i mean is that if the camera is facing forwards, and the character is facing backwards, have the sprite face the camera, but if the camera is facing forwards and the character is facing forwards, then show the back of the character instead

(i apologize if this is what you are already doing, i only skimmed over the last few posts)