I need better colissions

Hello I’m codding a strategy game about machine car fights, So I have semi working model,
I trying to fix the colissions of the machines and the play area fight, the thing I dont understand how I can code a better colissions yes they working but they not the thing I want(Some times the cars ignore the colission and countine the gameplay in same positions) Also I dont use the roblox psychics because I need use anchored parts.

Sorry for pasting the all script ( I need paste all because this the whole colission script I have Also you can use my model to test it quickly) You don’t have to write a new script just give a recommendation or a fix way to make it better.

 local mainhitbox = script.Parent
local WhellA = mainhitbox.WA
local WhellB = mainhitbox.WB
local WhellC = mainhitbox.WAn
local WhellD = mainhitbox.WBn

local XMemory = 0
local StartPos = mainhitbox.Position

local Rot = 1
local WRot = 1
local Debounce = 0

local Unadvantage = 0
local Slower = 1

local StuckEncounter = 0
local SecondaryCounter = 1.6

local XMine = mainhitbox.Size.X
local YMine = mainhitbox.Size.Y
local ZMine = mainhitbox.Size.Z

local TotalSelfP = XMine + YMine + ZMine

while wait() do

 	local StatsUI = mainhitbox.Stats.ImageLabel


	XMemory -= 7*Rot



	mainhitbox.Position = Vector3.new(mainhitbox.Position.X + 0.4*WRot - Unadvantage, mainhitbox.Position.Y, mainhitbox.Position.Z)

	WhellA.Rotation = Vector3.new(0, 0, XMemory)
	WhellB.Rotation = Vector3.new(0, 0, XMemory)
	WhellC.Rotation = Vector3.new(0, 0, XMemory)
	WhellD.Rotation = Vector3.new(0, 0, XMemory)

	WhellA.Position = Vector3.new(WhellA.Position.X + (0.4*WRot)/Slower - Unadvantage, WhellA.Position.Y, WhellA.Position.Z)
	WhellB.Position = Vector3.new(WhellB.Position.X + (0.4*WRot)/Slower - Unadvantage, WhellB.Position.Y, WhellB.Position.Z)
	WhellC.Position = Vector3.new(WhellC.Position.X + (0.4*WRot)/Slower - Unadvantage, WhellC.Position.Y, WhellC.Position.Z)
	WhellD.Position = Vector3.new(WhellD.Position.X + (0.4*WRot)/Slower - Unadvantage, WhellD.Position.Y, WhellD.Position.Z)
	
	
	StatsUI.Wrot.Text = WRot
	StatsUI.Unadvantage.Text = Unadvantage
	StatsUI.Stuck.Text = StuckEncounter
	StatsUI.Secondary.Text = SecondaryCounter
	StatsUI.Rot.Text = Rot
	
	if SecondaryCounter < 0 then
		SecondaryCounter = 0
	end
	
	
	StuckEncounter -= 0

	local Parts = mainhitbox

	for i,v in ipairs(Parts:GetDescendants()) do
		if v.Name == ("WA") or v.Name == ("WBn") then
			v.Size = v.Size + Vector3.new(.01,.01,.01)
			local touchingParts = v:GetTouchingParts()
			v.Size = v.Size - Vector3.new(.01,.01,.01)


			for _, part in pairs(touchingParts) do
				if part.Name == "BorderA" or part.Name == "WA" or part.Name == "WAn" or part.Name == "WB" or part.Name == "WBn" and Debounce == 0 then

					if part.Name == "WAn" or part.Name == "WB" or part.Name == "WBn" or part.Name == "WA" then
						WRot = 1


						local XPower = part.Parent.Size.X
						local YPower = part.Parent.Size.Y
						local ZPower = part.Parent.Size.Z

						local TotalEnemyP = XPower + YPower + ZPower

						local XMine = mainhitbox.Size.X
						local YMine = mainhitbox.Size.Y
						local ZMine = mainhitbox.Size.Z

						local TotalSelfP = XMine + YMine + ZMine

						--if TotalSelfP - TotalEnemyP > 0 then
						--	Unadvantage = -0.2
						--else
						--	Unadvantage = -0.2
						--end

						Unadvantage = 0
						mainhitbox.Position = Vector3.new(mainhitbox.Position.X + -0.55*WRot - Unadvantage, mainhitbox.Position.Y, mainhitbox.Position.Z)
						WhellA.Position = Vector3.new(WhellA.Position.X + -0.55*WRot, WhellA.Position.Y, WhellA.Position.Z)
						WhellB.Position = Vector3.new(WhellB.Position.X + -0.55*WRot, WhellB.Position.Y, WhellB.Position.Z)
						WhellC.Position = Vector3.new(WhellC.Position.X + -0.55*WRot, WhellC.Position.Y, WhellC.Position.Z)
						WhellD.Position = Vector3.new(WhellD.Position.X + -0.55*WRot, WhellD.Position.Y, WhellD.Position.Z)
						---Rot = Rot*-1
						--WRot = Rot
						Debounce = 1

						Debounce = 1
						
					
						

					else
						print("BorderA")
						Unadvantage = 0
						mainhitbox.Position = Vector3.new(mainhitbox.Position.X + -0.55*WRot - Unadvantage, mainhitbox.Position.Y, mainhitbox.Position.Z)
						WhellA.Position = Vector3.new(WhellA.Position.X + -0.55*WRot, WhellA.Position.Y, WhellA.Position.Z)
						WhellB.Position = Vector3.new(WhellB.Position.X + -0.55*WRot, WhellB.Position.Y, WhellB.Position.Z)
						WhellC.Position = Vector3.new(WhellC.Position.X + -0.55*WRot, WhellC.Position.Y, WhellC.Position.Z)
						WhellD.Position = Vector3.new(WhellD.Position.X + -0.55*WRot, WhellD.Position.Y, WhellD.Position.Z)
						Rot = Rot*-1
						WRot = Rot
						Debounce = 1
						StuckEncounter += 0.12



					end

				end
			end
		end
	end

	if StuckEncounter > 2 then
		SecondaryCounter += 0.5 + TotalSelfP/27
		Unadvantage = 0
		mainhitbox.Position = Vector3.new(mainhitbox.Position.X + ((TotalSelfP)/27)*SecondaryCounter*WRot, mainhitbox.Position.Y, mainhitbox.Position.Z)
		WhellA.Position = Vector3.new(WhellA.Position.X + ((TotalSelfP)/27)*SecondaryCounter*WRot, WhellA.Position.Y, WhellA.Position.Z)
		WhellB.Position = Vector3.new(WhellB.Position.X + ((TotalSelfP)/27)*SecondaryCounter*WRot, WhellB.Position.Y, WhellB.Position.Z)
		WhellC.Position = Vector3.new(WhellC.Position.X + ((TotalSelfP)/27)*SecondaryCounter*WRot, WhellC.Position.Y, WhellC.Position.Z)
		WhellD.Position = Vector3.new(WhellD.Position.X + ((TotalSelfP)/27)*SecondaryCounter*WRot, WhellD.Position.Y, WhellD.Position.Z)
		Debounce = 1

		StuckEncounter = 0
	end
end



Custom physics is definitely not a way to do this. Especially with the code you came with

This function is outdated and should never be used in newer projects. Described in here:
https://create.roblox.com/docs/reference/engine/classes/BasePart#GetTouchingParts
Even if you replace it with it’s newer counterpart. This code will still be hard to compute. Please switch to Roblox Physics, as it’s way more optimized and stable. Just switch network ownership to server so players won’t be able to exploit it.

1 Like

Well I have years of old codding information yes you’re right on the outdated section but I dont know how to use roblox psychics on anchored parts only in x position How I can do that?

1 Like

As I mentioned, you have to play around with network ownership to make it work properly for players. But if you plan to make physics only on server, then just use it in a server script and it will work just fine

local Parent = script.Parent
local NewVector3 = Vector3.new
local StartPos = Parent.Position
local ConstantY = StartPos.Y
local ConstantZ = StartPos.Z

game:GetService("RunService").Heartbeat:Connect(function()
	Parent.Position = NewVector3(Parent.Position.X,ConstantY,ConstantZ)
end)
2 Likes

Thanks for reply and recommendation I will try it.

1 Like