Making my physics-based interaction system more reliable

so I made a physics-based interaction system along the lines of Amnesia: The Dark Descent (also inspired by one Tyridge77 once made but I don’t think his test place for it is active anymore so I can’t get a reference of it).

It works mostly okay except that the movement isn’t very ideal. It’s very deterministic of where you’re standing. For example, if I stand to the left of the valve seen in the video I cannot turn it fully. You can also see in the video it’s almost impossible to turn in third person (although this is meant for a first person horror game, I want to realise this system to the public and I don’t want to have that limitation)

This is the code that handles moving the clicked part with the mouse.

local lv = CFrame.new(hRP.Position,mouse.Hit.p) 
bP.position=(hRP.Position+lv.lookVector*2) --bP is a body position,hRP is the player character's humanoid root part.

What can I do to make it work better? I wouldn’t mind moving from the physics based aspect since that would probably make it more stable(I mostly did used physics since it made it easier to move the parts).

2 Likes

So,instead of lv being positioned at the root part, it should probably be set to the camera CFrame position.
This will help with the 3rd person perspective.

Also, i see that you multiply lv.lookVector by 2.
Instead, multiply it by the distance between lv’s position and the intractable object to give a more consistent feel.

local cam = workspace.CurrentCamera
local intractableObj = --... 
local lv = CFrame.new(cam.CFrame.p, mouse.Hit.p) 
bP.position=(lv.p + lv.lookVector * (intractableObj.Position-lv.p).magnitude)

It may also be worth setting the mouse’ TargetFilter’ to either the workspace or the interstate object, which should also improve consistency.

mouse.TargetFilter = workspace
Although, remember to null this when you let go of the interactive object. :stuck_out_tongue_winking_eye:

Thanks! It seems switching to using the camera instead of root part has worked.

Also, I was originally doing it by distance, but multipying it by 2 felt like it worked better for some reason.

1 Like