Trying to make a simple repulsion system

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I’m making a 3D Metroidvania that locks the camera in the z axis and makes it impossible for the player to move on the z axis. In this game I want to make a slash like attack that repels the user off whatever surface they hit, or if they’re midair, keeps them levitating for a little bit.

  1. What is the issue? Include screenshots / videos if possible!

The limitations arised when I was testing out ways to repel myself off the swinging the direction from both left and right corners of the screen. Whenever I would slash in any of these directions, I would get repelled off far off into the z axis which is what I don’t want.

^ Video demonstrating this.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

if Humanoid:GetState() ~= Enum.HumanoidStateType.Jumping then
				Humanoid.Jump = true

				local InstaAttach = Instance.new("Attachment", HRP)
				InstaAttach.Name = "InstaAttach"

				local LinearVelocity = Instance.new("LinearVelocity", HRP)
				LinearVelocity.Attachment0 = InstaAttach
				LinearVelocity.MaxForce = math.huge
				LinearVelocity.RelativeTo = Enum.ActuatorRelativeTo.Attachment0

				LinearVelocity.VectorVelocity = Vector3.new(40, 40, 0)

				Debris:AddItem(LinearVelocity, 0.2)
				Debris:AddItem(InstaAttach, 0.2)

			else
				local InstaAttach = Instance.new("Attachment", HRP)
				InstaAttach.Name = "InstaAttach"

				local LinearVelocity = Instance.new("LinearVelocity", HRP)
				LinearVelocity.Attachment0 = InstaAttach
				LinearVelocity.MaxForce = math.huge
				LinearVelocity.RelativeTo = Enum.ActuatorRelativeTo.Attachment0

				LinearVelocity.VectorVelocity = Vector3.new(40, 40, 0)

				Debris:AddItem(LinearVelocity, 0.2)
				Debris:AddItem(InstaAttach, 0.2)
			end

^ This is the script above.

I’ve been playing around with both LinearVelocity and Lineforce but nothing can get the results I want.

^ This is what I want in drawing form.

If you can think of anything that can help me even a little bit then I’ll take it. Much appreciated.

I’m not super familiar with the physics constraints, but to me it seems that this

LinearVelocity.RelativeTo = Enum.ActuatorRelativeTo.Attachment0

Should instead be

LinearVelocity.RelativeTo = Enum.ActuatorRelativeTo.World
1 Like

Here I was thinking it was gonna be complex, but I just simply misunderstood how the new physics constraints work. Works like a charm, thank you and have a good day!

1 Like