I’ve decided to revisit an old project of mine from a few months prior, I’ve completely scraped the old, buggy mechanics and am currently working on new mechanics.
My problem is that when two balls touch, they do not fire ‘Radiation’ particles at each other.
Bonds are formed when two spheres touch. Prior to making bonds the spheres would send these ‘Raditaion’ particles in every direction. If a particle from a different cell is detected, the sphere would follow the particle’s path.
Once bonds are made, to secure the bond the spheres would fire particles at each other to not lose contact. In an update bonds would be broken if contact breaks.
Here’s the code that is run when making each particle:
if bond then
rad.CFrame = CFrame.lookAt(rad.Position,bond.Position)
else
rad.Orientation = Vector3.new(ran(0,255),ran(0,255),ran(0,255))
end
(bond refers to the bonded BasePart, rad refers to the Radiation BasePart)
I’ve tried CFrame.lookAt and bond.Position-rad.Position, techniques that I’ve found on the forum and external sources. It’s either my incorrect usage or context.
local cell = script.Parent
local ran = math.random
local PhyServ = game:GetService('PhysicsService')
local bond : BasePart = nil
PhyServ:RegisterCollisionGroup('Cells')
PhyServ:RegisterCollisionGroup('Rads')
PhyServ:CollisionGroupSetCollidable('Cells','Cells',true)
PhyServ:CollisionGroupSetCollidable('Cells','Rads', false)
PhyServ:CollisionGroupSetCollidable('Rads','Rads',false)
cell.CollisionGroup = 'Cells'
local function des(p)
task.wait(5)
p:Destroy()
end
local function radmeet(rad:BasePart)
if rad.Parent ~= cell and rad.Name == 'rad' then
cell.Orientation = rad.Orientation*Vector3.new(-1,-1,1)
elseif rad.Name == 'Cell' then
bond = rad
end
end
cell.Touched:Connect(radmeet)
while true do
task.wait(.05)
local rad = Instance.new("Part")
rad.Parent = cell
rad.Transparency = .5
rad.Color = Color3.new(200,0,0)
rad.Size = Vector3.new(.2,.2,.2)
rad.Position = cell.Position
rad.Shape = Enum.PartType.Block
if bond then
rad.CFrame = CFrame.lookAt(rad.Position,bond.Position)
else
rad.Orientation = Vector3.new(ran(0,255),ran(0,255),ran(0,255))
end
local linvel = Instance.new('LinearVelocity')
linvel.Parent = rad
linvel.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
linvel.VelocityConstraintMode = Enum.VelocityConstraintMode.Vector
linvel.VectorVelocity = Vector3.new(3,0,0)
local atc = Instance.new('Attachment')
atc.Parent = rad
linvel.Attachment0 = atc
rad.Name = 'rad'
linvel.MaxForce = 99999999
rad.CanCollide = false
task.spawn(des,rad)
rad.CollisionGroup = 'Rads'
end
I’ve tried changing the axis but I was changing it on the wrong variable.
Here’s my final product. I’ve added functionality for cell bonds to be divorced, and when cells are bonded their radiation particles lifetime is shorter and the cells are more responsive to these particles.
local cell = script.Parent
local ran = math.random
local PhyServ = game:GetService('PhysicsService')
local bond : BasePart|false = false
local tbond : number = 0
PhyServ:RegisterCollisionGroup('Cells')
PhyServ:RegisterCollisionGroup('Rads')
PhyServ:CollisionGroupSetCollidable('Cells','Cells',true)
PhyServ:CollisionGroupSetCollidable('Cells','Rads', false)
PhyServ:CollisionGroupSetCollidable('Rads','Rads',false)
cell.CollisionGroup = 'Cells'
local function des(p)
task.wait(1)
if not bond then task.wait(3) end
p:Destroy()
end
local function celldivorce(b)
task.spawn(function()
if b == bond then
local savedtbond = tbond
task.wait(2)
if tbond == savedtbond and b == bond then
bond = false
end
end
end)
end
local function radmeet(rad:BasePart)
if rad.Parent ~= cell and rad.Name == 'rad' then
cell.Orientation = rad.Orientation*Vector3.new(-1,-1,-1)
if bond ~= false then
cell.LinearVelocity.VectorVelocity = Vector3.new(0,0,-3)
else
cell.LinearVelocity.VectorVelocity = Vector3.new(0,0,-.5)
end
elseif rad.Name == 'Cell' then
bond = rad
tbond+=1
end
end
cell.Touched:Connect(radmeet)
cell.TouchEnded:Connect(celldivorce)
while true do
task.wait(.05)
if bond then task.wait(.1) end
local rad = Instance.new("Part")
rad.Parent = cell
rad.Transparency = .5
rad.Color = Color3.new(200,0,0)
rad.Size = Vector3.new(.2,.2,.2)
rad.Position = cell.Position
rad.Shape = Enum.PartType.Block
if bond then
rad.CFrame = CFrame.lookAt(rad.Position,bond.Position)
else
rad.Orientation = Vector3.new(ran(0,255),ran(0,255),ran(0,255))
end
local linvel = Instance.new('LinearVelocity')
linvel.Parent = rad
linvel.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
linvel.VelocityConstraintMode = Enum.VelocityConstraintMode.Vector
linvel.VectorVelocity = Vector3.new(0,0,-3)
local atc = Instance.new('Attachment')
atc.Parent = rad
linvel.Attachment0 = atc
rad.Name = 'rad'
linvel.MaxForce = 99999999
rad.CanCollide = false
task.spawn(des,rad)
rad.CollisionGroup = 'Rads'
if not table.find(cell:GetTouchingParts(),bond) then
bond = false
end
end