Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Help with positioning in Mouse Pickup Script?

local Mouse = game.Players.LocalPlayer:GetMouse()

local PickForce = Instance.new('BodyPosition')
PickForce.P = 100000
PickForce.D = 7000
local TargetObject = nil

game["Run Service"].RenderStepped:connect(function()
	PickForce.position = Vector3.new(game.Players.LocalPlayer.Character.Torso.Position.X, game.Players.LocalPlayer.Character.Torso.Position.Y, game.Players.LocalPlayer.Character.Torso.Position.Z * 5)
end) -- Need help in this function

Mouse.Button1Down:connect(function()
	if Mouse.Target then
		local p = Mouse.Target
		if (game.Players.LocalPlayer.Character.Torso.Position - p.Position).magnitude <= 30 then
			PickForce.Parent = p
		else
			PickForce.Parent = nil
		end
	else
		PickForce.Parent = nil
	end
end)

This script is intended to imitate the ability to lift objects in horror games. I am having lots of trouble finding a good algorithm for the bodyposition.

I only need help with the positioning, I will fix a few direct references to the character soon.

1 answer

There could be a number of problems going on here.

  1. Make sure the part is unanchored and not part of a model.

  2. You should probably do some checking to make sure its something you want to interact with (i.e. is an item and not the floor).

  3. Also the Z reference would be for pushing the part away and I would ADD 5 instead of multiplying it by 5, so that its 5 studs pushed away, instead of some very high, random value (whatever Z might be)

You might consider moving a whole model, instead of one part. In such case, I recommend setting the PrimaryPart of the model and then using SetPrimaryPartCFrame method to the position you would like - instead of using BodyPosition . You can even CFrame it to the position you want, using a loop and the SetPrimaryPartCFrame positioning method I suggest.

I haven't seen what these horror games do, so I might to check one out to see if they're using physics or CFraming.

This discussion is preserved as it was. New answers, comments, and votes are closed.