Problems with collisions

I’m currently trying to make the next tree anchor itself only when it touches the ground, but right now it’s anchoring before it actually makes contact.

Specifically, the tree anchors as soon as the process starts, even though the pink part — which is supposed to be the contact point — hasn’t touched the ground yet.

I’ve attached some screenshots to show what’s happening. The pink area is the part that should be touching the ground before anchoring occurs. I’d really appreciate any help or suggestions on how to fix this behavior.

function(Model,all)
				local pivot = Model.Pivote::BasePart
				pivot.Anchored = false

				
				pivot:SetNetworkOwner(nil) 
			    all.ProximityPrompt:destroy()
				
				local randomDirection = Vector3.new(
					math.random() - 0.5, -- eje X
					0,                  
					math.random() - 0.5  -- eje Z
				).Unit

				local forceMagnitude = 5000+ (500*all.Size)
				local impulse = randomDirection * forceMagnitude

				pivot:ApplyImpulse(impulse)
				
				local hitpart = all.Model.HitPart::BasePart
				
				local onTouchTerrain = hitpart.Touched:Connect(function(hit)
					if hit:HasTag("Floor") then
						--task.wait(3)
						print("Touched")
						pivot.Anchored = true
						pivot.AssemblyLinearVelocity = Vector3.new(0,0,0)
						pivot.AssemblyAngularVelocity = Vector3.new(0,0,0)
						
					end
				end)
				
				
		end,

Hey! I saw your post and the script you shared — you’re doing a great job so far with the tree system!

From what you described and the image you posted, it looks like the tree is anchoring too early, before the pink part (which I assume is your HitPart) actually touches the ground.

I believe the issue is that .Touched might be firing immediately upon spawn due to physics interactions with nearby parts or even grass/leaves. That can cause the tree to anchor prematurely.

Here’s a potential solution:

You could add a small debounce or check to ensure that the part hitting the floor is actually below a certain Y-position threshold (to ensure it hit the ground, not another part).

Here’s how you might change your code:

local hasAnchored = false
local hitPart = all.Model.HitPart :: BasePart

local onTouchTerrain = hitPart.Touched:Connect(function(hit)
    if hasAnchored then return end

    -- Optional: Tag check to ensure it's really the ground
    if hit:HasTag("Floor") then
        -- Optional: Y-position check to ensure it's close enough to the ground
        if hitPart.Position.Y <= someYThreshold then
            print("Touched")
            hasAnchored = true
            pivot.Anchored = true
            pivot.AssemblyLinearVelocity = Vector3.new(0,0,0)
            pivot.AssemblyAngularVelocity = Vector3.new(0,0,0)
        end
    end
end)

You just need to define someYThreshold depending on your scene setup — maybe something like 5 or 10, or relative to the terrain height.

Alternatively, if the Touched event is too inconsistent, consider using a Region3 check or Raycasting downward from the HitPart to detect terrain more precisely before anchoring.

1 Like

How can I do that using raycasting? I’m still pretty new to programming, so any explanation or example would really help.

1 Like

There is an article on Roblox that talks about this: Raycasting | Documentation - Roblox Creator Hub

1 Like

Did you mistakenly make other Parts with the tag Floor?

Try this:

					if hit:HasTag("Floor") then
						print("Touched ", hit.Name)

This also may be a server/client issue.
Try testing it by hitting the Play button with 2 players to see if the server version of the tree is anchored with the pink part touching the terrain, but the clients show the tree still in the air.

1 Like

I’m going to use raycasting I think it’s more reliable. Thanks.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.