Download

How can i make this type of magnetism (Grabbing something)

Hi guys. Im trying to make something like this https://youtu.be/lPdVyq9J138?t=21s, My game is sort of a topdown view, and i want to be able to trace from player position forward. And if the trace hit an object, grab that object, so if i move backwards lets say, the object also moves backwards with me. Like if we are linked. Then after i could press other keys to make the object come to me, or make the object go away, if i stop pressing the key or if i move the object far away, the object should unlinked with me and go back to its normal state.

I have the part where i trace forward from the player, but i dont know how to link the other object i hit with me, so if i move the objject moves.
Any direction, any help, any sample blueprint would be appreciated. Thanks.

Could try something like this (In the character blueprint):

t4PFyQY.png

You’ll need a way to filter what can be grabbed, I just did this by adding the prefix “MC” in the level editor, and only attaching the actor if it has that prefix in its name.

And for moving the object towards or away from the player:

mhsF4t4.png

The timeline is 3 seconds long with a float that goes from 0 to 1. You could do that in other ways.
It’s not commented or anything, if there’s something that doesn’t make sense just ask. There is probably better ways to do it too.

Edit: These won’t have any collision though as their location is being set every tick…

Physics handle is the way to go, it is designed just for this. Real easy to implement too in both Cpp and BP and allows for collisions.

How I use a physics handle:

I add a physics handle component to my character, I perform a line trace, set the physics handle location and rotation (I set rotation to camera’s rotation, set location to a few meters in front of camera), then call grab component, feeding in the component output from the trace. To drop, simply call ‘release component’…It works a charm.

Hi again, thanks for appointing me to use physics handle, i did this tutorial https://wiki.unrealengine.com/Pick_Up_Physics_Object_Tutorial and its working right now. The only problem i got is that i dont want the things i grab, to rotate in their local axis while i rotate or move. c646f348bdcd6739dbd6dee68da59782460a98e7.png

In this image i grab BOX 1 and when i rotate it does a rare rotation around its own axis. I want to be able to grab it and the box should stay static on its local rotation, but just move left or right maintaining the distance from where i grab it. Lets say i grab BOX 2, so when i rotate, BOX 2 should rotate maintaing a distance, but not rotating on its local axis.

Thnaks

I fixed my last problem changing how Grab Component constraint bool to true. But now i have anothe rproblem. How i can make based on this blueprint im using to change Other Item location based on what keys im pressing. I want to be able to move away or attract the object towards me, i know it have something to do with other item location, But i couldnt manage to make a blueprint that works to do that. Here is my blueprint.

Capture1.PNG
Capture2.PNG
f8661b4e920d308836c37923be7f3c6333e94b0c.png

Thanks

Exactly as you said, setting the variable ‘Other Item Location’ should do the trick…you’d probably want to interpolate between the variables current value and the target value.

Hey ULLS, i tried using FInterp and a timeline, but it doesnt work. I dont know how to use them to change the location. I just want to add or substract to Other item location by 1 when pressing left mouse button. But in blueprints i dont jnow how to do it, maintaining the distance from the player form where i first grab it.