How to detect players jumping over barrels?

I’m making a Donkey Kong game and in the first level you have these rolling barrels, now I want to detect when a player jumps over a barrel so that they get to score points like in the original arcade.
I have no idea how I would do this …
Any ideas?
In the video you get to see the barrels:

2 Likes

Would be inefficient but you canput an object above the player and when the player touches it you give em score

Perhaps add score every time 10 seconds passed instead?

3 Likes

I want that points can only be earned by jumping over a barrel, but thanks for the idea

1 Like

Maybe you could try raycasting

3 Likes

Maybe you can weld a part to the barrels that gives the player a point when they touch it?

4 Likes

Wouldn’t the barrels rolling cause a problem, how does that work?

1 Like

Turn CanCollide off, turn CanTouch on, should work perfectly.

2 Likes

Using Raycast can help detect players jumping over barrels. I’m not sure if the code below will work but you can try it. Correct me if I’m wrong. Then you can use RunService to repeat the process of raycasting then maybe once it detect you can disconnect the RunService

local function detect_on_top(barrel, how_much_studs_upwards)
	local raycast_params = RaycastParams.new()
	-- put whatever parameters you want to blacklist the barrel from being raycasted or something
	local rayresult = workspace:Raycast(barrel.Position, Vector3.yAxis * how_much_studs_upwards, raycast_params)

	if rayresult then
		local char = rayresult.Instance:FindFirstAncestorOfClass("Model")
		if char then
			if game.Players:GetPlayerFromCharacter(char) then
				return true
			end
		end
	end
	return false
end
2 Likes

Why use run service ?? Why not just use humanoid. Jumping??

1 Like

Because then it will only trigger at player jump state and when player jump they could be in front of the barrel instead of on top of the barrel

1 Like

I see… Thx for the info

charssssssss