How to prevent the character from being "run over" by an object moved by the mouse?

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…

image

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?

You can try to anchor the player’s root part.

1 Like

I don’t want to stop the player from moving while I insert pieces.

If I set Player.Character.PrimaryPart.Anchored = true, the player will no longer be “run over” by the piece, but also will no longer be able to move.

Perhaps the most correct solution is to detect when the player is hit by a piece and ONLY AT THIS MOMENT prevent him from suffering this impact.

Any ideas on how to do 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

Wouldn’t setting your WalkSpeed and JumpPower to 0 help?

You should take a look at PhysicsService:

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:

4 Likes

Here is what happens:
a

Here the sample project to simulate:

Baseplate.rbxl (25.9 KB)

You could do something with magnitudes or something. Or just use Touched and TouchEnded to anchor your player’s rootpart

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.

Yes. But the part needs to keep colliding with everything else but colliding with the player.

Then use collision groups from Physics service. Thats what you need.

Play around with collision groups!

2 Likes

Hacky way.

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)

Baseplate2.rbxl (26.1 KB)

1 Like

I created a workaround as follows:

  1. When the object is being moved by the mouse, I anchor the character.
  2. Meanwhile, if any character’s movement key is pressed (WASD etc), I unanchor the character until this key is released, when I anchor it again.

This worked well, but it was a strange sequel:

I’ve tried to use the Collision Group based on this example:

… which is similar to this example:

… both cases using ServerScript… but it’s not working…

1 Like

Did you add the collision group to the moving piece?

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)

What am I doing wrong?

Don’t forget the accessories, there’s usually a part named Handle inside of the accessory

This should be as simple as changing GetChildren() in the player added to GetDescendants()

Yeah, should be simple.
Have anyone tested with my last attached project?