Jump on decal using editable image

  1. What do you want to achieve? How do I make my jump prototype smooth?

local ImageObject = script.Parent

local EditableImage = Instance.new("EditableImage")
EditableImage.Size = Vector2.one * 1024
EditableImage.Parent = ImageObject


local startPosition : Vector2 = Vector2.new(EditableImage.Size.X/3, 150)
local updatedPosition : Vector2


EditableImage:DrawRectangle(Vector2.zero, EditableImage.Size, Color3.new(0, 1, 1), 0)
EditableImage:DrawRectangle(Vector2.zero, Vector2.new(EditableImage.Size.X/3, EditableImage.Size.Y), Color3.new(0, 1, 0), 0)
EditableImage:DrawRectangle(startPosition, Vector2.new(EditableImage.Size.X/7, EditableImage.Size.Y/7), Color3.new(1, 0, 0), 0)

local KeysBeingPressed = {
	Up = false,
	Left = false,
	Down = false,
	Right = false,
	Space = false
}

local uis = game:GetService("UserInputService")
local runService = game:GetService("RunService")

local height = 0

local function jump(Pos : Vector2)
	EditableImage:DrawRectangle(Pos + Vector2.new(50, 0), Vector2.new(EditableImage.Size.X/7, EditableImage.Size.Y/7), Color3.new(1, 0, 0), 0)
end

local function drawBackground()
	EditableImage:DrawRectangle(Vector2.zero, EditableImage.Size, Color3.new(0, 1, 1), 0)
	EditableImage:DrawRectangle(Vector2.zero, Vector2.new(EditableImage.Size.X/3, EditableImage.Size.Y), Color3.new(0, 1, 0), 0)
end

local function DrawPlayer(y : number, x : number, t)
	drawBackground()

	updatedPosition = startPosition + Vector2.new(y, x)
	updatedPosition = Vector2.new(math.max(updatedPosition.X, EditableImage.Size.X/3), math.max(updatedPosition.Y, 100))
	height = updatedPosition.X

	if math.floor(height) ~= math.floor(EditableImage.Size.X/3) then 
		EditableImage:DrawRectangle(updatedPosition, Vector2.new(EditableImage.Size.X/7, EditableImage.Size.Y/7), Color3.new(1, 0, 0), 0)
		startPosition = updatedPosition

	elseif t  == true then
		EditableImage:DrawRectangle(updatedPosition + Vector2.new(50, 0), Vector2.new(EditableImage.Size.X/7, EditableImage.Size.Y/7), Color3.new(1, 0, 0), 0)
		startPosition = updatedPosition + Vector2.new(50,0)
		task.wait(1) -- time when the jump ends
		drawBackground()
		EditableImage:DrawRectangle(updatedPosition - Vector2.new(50, 0), Vector2.new(EditableImage.Size.X/7, EditableImage.Size.Y/7), Color3.new(1, 0, 0), 0)
		startPosition = updatedPosition - Vector2.new(50,0)
	elseif math.floor(height) == math.floor(EditableImage.Size.X/3) then
		EditableImage:DrawRectangle(updatedPosition, Vector2.new(EditableImage.Size.X/7, EditableImage.Size.Y/7), Color3.new(1, 0, 0), 0)
		startPosition = updatedPosition

	end
end

uis.InputBegan:Connect(function(input : InputObject)
	if input.KeyCode == Enum.KeyCode.W or input.KeyCode == Enum.KeyCode.Up or input.KeyCode == Enum.KeyCode.DPadUp then
		KeysBeingPressed[1] = true
	elseif input.KeyCode == Enum.KeyCode.A or input.KeyCode == Enum.KeyCode.Left or input.KeyCode == Enum.KeyCode.DPadLeft then
		KeysBeingPressed[2] = true
	elseif input.KeyCode == Enum.KeyCode.S or input.KeyCode == Enum.KeyCode.Down or input.KeyCode == Enum.KeyCode.DPadDown then
		KeysBeingPressed[3] = true
	elseif input.KeyCode == Enum.KeyCode.D or input.KeyCode == Enum.KeyCode.Right or input.KeyCode == Enum.KeyCode.DPadRight then
		KeysBeingPressed[4] = true
	elseif input.KeyCode == Enum.KeyCode.Space then
		KeysBeingPressed[5] = true
	end
end)

uis.InputEnded:Connect(function(input : InputObject)
	if input.KeyCode == Enum.KeyCode.W or input.KeyCode == Enum.KeyCode.Up or input.KeyCode == Enum.KeyCode.DPadUp then
		KeysBeingPressed[1] = false
	elseif input.KeyCode == Enum.KeyCode.A or input.KeyCode == Enum.KeyCode.Left or input.KeyCode == Enum.KeyCode.DPadLeft then
		KeysBeingPressed[2] = false
	elseif input.KeyCode == Enum.KeyCode.S or input.KeyCode == Enum.KeyCode.Down or input.KeyCode == Enum.KeyCode.DPadDown then
		KeysBeingPressed[3] = false
	elseif input.KeyCode == Enum.KeyCode.D or input.KeyCode == Enum.KeyCode.Right or input.KeyCode == Enum.KeyCode.DPadRight then
		KeysBeingPressed[4] = false
	elseif input.KeyCode == Enum.KeyCode.Space then
		KeysBeingPressed[5] = false
	end
end)

local function onPreRender()
	if KeysBeingPressed[1] then 
		--DrawPlayer(4, 0, false)
	elseif KeysBeingPressed[2] then 
		DrawPlayer(0, -4, false)
	elseif  KeysBeingPressed[3] then 
		--DrawPlayer(-4, 0, false)
	elseif  KeysBeingPressed[4] then 
		DrawPlayer(0, 4, false)
	elseif  KeysBeingPressed[5]  or KeysBeingPressed[2] and KeysBeingPressed[5] or KeysBeingPressed[4] and KeysBeingPressed[5] then
		DrawPlayer(0,0, true)
	end 
end

runService.PreRender:Connect(onPreRender)

Any help will be appreciated!

1 Like

you can make this faster by not using editable images

yeah, thats right, but I want to make it on cylinder shape and train with editable image

Why not just have the background image and use a red Part (or a Union if you have a curved surface) that moves with the inputs using CFraming or Tweening?

1 Like

it would be a good idea, but I realized that it would no longer be similar to what I originally wanted to do.