In my game, I move some pieces with the mouse.
These pieces are already normally avoiding collisions with the character.
But, for some reason, in some quick moves, the collision is not respected and the character is “run over” by the pieces, thus…
I would like that, at the moment when I am moving the pieces with the mouse, the character would remain immobile, fixed as a rock, to avoid being run over.
How do I define this?
Try running a loop through all the descendants of the character, checking if it is a BasePart, then setting it’s Anchored property to true. Make sure to have a way to reverse this
Assign different collision groups to your parts and player character parts, and make those collision groups non-collidable. I dont really have time to include the code, sorry, but heres some useful functions:
So what exactly are trying to achieve (because i didnt get it from the original post)?
Are you trying to make the part not collidable with the player’s character? Or are you trying to make the player’s character stay in place while moving the part around?
From what I see your problem is that you are moving the part - which is collidable with player’s character - to the character and roblox cant catch up the collision calculations so it results in character “flinging”. Try making the part (not the character) non-collidable at all (part.CanCollide = false); if that wont work or breaks something, try using collision groups from Physics service to manipulate collisions.
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Part = workspace.Part;
local Character = Player.Character or Player.CharacterAdded:Wait();
local Head = Character:WaitForChild'Head';
UserInputService.InputChanged:Connect(function(Input, GPE)
if Input.UserInputType == Enum.UserInputType.MouseMovement then
local P = Mouse.Hit.Position
local Dis1 = Vector3.new(Head.Position.X,0,Head.Position.Z);
local Dis2 = Vector3.new(P.X, 0, P.Z);
if ((Dis1-Dis2).Magnitude < (Part.Size.X + Part.Size.Z) / 2) then
return;
end;
Part.CFrame = CFrame.new(P.X, 5, P.Z);
end
end)
Do you mean instead to add the moving piece to the collision group?
Sorry, I have no experience with this.
As I said above, I added this Server Script, which didn’t work:
Original Server Script
local PS = game:GetService("PhysicsService")
PS:CreateCollisionGroup("Player")
PS:CollisionGroupSetCollidable("Player","Player",false)
PS:SetPartCollisionGroup(workspace.Part,"Player")
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
Character:WaitForChild("HumanoidRootPart")
Character:WaitForChild("Head")
Character:WaitForChild("Humanoid")
for i,v in pairs(Character:GetChildren()) do
if v:IsA("BasePart") then
print('ok')
PS:SetPartCollisionGroup(v,"Player")
end
end
end)
end)
Then I added the workspace.Part to the “Player” collision group (PS:SetPartCollisionGroup(workspace.Part,"Player") , but also didn’t work:
Added to the Original Script
local PS = game:GetService("PhysicsService")
PS:CreateCollisionGroup("Player")
PS:CollisionGroupSetCollidable("Player","Player",false)
PS:SetPartCollisionGroup(workspace.Part,"Player")
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
Character:WaitForChild("HumanoidRootPart")
Character:WaitForChild("Head")
Character:WaitForChild("Humanoid")
for i,v in pairs(Character:GetChildren()) do
if v:IsA("BasePart") then
print('ok')
PS:SetPartCollisionGroup(v,"Player")
end
end
end)
end)
Here my current updated sample project: Baseplate.rbxl (26.7 KB)