I am creating a BMX game at the moment and I am trying to create the ability to do a backflip. I have managed to make most of the bike and the player do a flip but the fork and handlebars stay still. The trick is written in a module script that fires when the player presses are certain key (in this case "R")

If anybody knows how to make the handlebars move as well it would be much appreciated if they could let me know how to make that happen.

Here is the bit of code that fires the tricks

UserInputService.InputBegan:connect(function(inputObject, processed)
	if not processed then
		if inputObject.KeyCode == Enum.Font.Code then
			if grounded then
				CHARACTER.Velocity	= CHARACTER.Velocity + floor * JUMP
			end
		elseif inputObject.KeyCode == Enum.KeyCode.E and grounded == false then
			EVENTS.Trick:Fire(CHARACTER, "Test")
		elseif inputObject.KeyCode == Enum.KeyCode.Q and grounded == false then
			EVENTS.Trick:Fire(CHARACTER, "SupSeat")
		elseif inputObject.KeyCode == Enum.KeyCode.W and grounded == false then
			EVENTS.Trick:Fire(CHARACTER, "Suicide")
		elseif inputObject.KeyCode == Enum.KeyCode.R and grounded == false then
			EVENTS.Trick:Fire(CHARACTER, "Backflip")
		end
	end
end)

And here is the code in the trick module script:

local TRICK = {}

function TRICK.Create(self, character, char, bike)
	local trick	= {
		Start	= tick();
		Length	= 0.6;
	}

	function trick.UpdateBike(self)
		local alpha	= math.clamp((tick() - self.Start) / self.Length, 0, 1)
		local lerp	= -math.abs(2*alpha - 1)^2 + 1

		local offset	= bike.Forks.CFrame:toObjectSpace(bike.Frame.CFrame)

		bike.Frame.CFrame	= bike.Frame.CFrame:Lerp(bike.Frame.CFrame * CFrame.Angles(-alpha * math.pi * -2, 0, 0), lerp)		
	end

	function trick.UpdateChar(self)
		local alpha	= math.clamp((tick() - self.Start) / self.Length, 0, 1)
		local lerp	= -math.abs(2*alpha - 1)^2 + 1
	end

	return trick
end

return TRICK

Here is the game if it helps: https://web.roblox.com/games/11905386108/Mega-Ramp-Game-BMX Controls: Spacebar to pedal LeftShift to brake A/D or move camera to steer Q = Superman W = Suicide no hander E = Barspin R = Not quite a backflip

1 comment

0

I use HingeConstraints to move the steering wheel of my vehicle by just adjusting the TargetAngle, you can try that.