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

**URL:** <https://forums.unrealengine.com/t/how-can-i-make-this-type-of-magnetism-grabbing-something/24063>\
**Category:** Blueprint\
**Tags:** unreal-engine\
**Created:** [March 13, 2015, 5:58am UTC](https://forums.unrealengine.com/t/how-can-i-make-this-type-of-magnetism-grabbing-something/24063 "2015-03-13T05:58:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aenopix](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Aenopix](https://forums.unrealengine.com/u/Aenopix)\
**Post date:** [March 13, 2015, 5:58am UTC](https://forums.unrealengine.com/t/how-can-i-make-this-type-of-magnetism-grabbing-something/24063/1 "2015-03-13T05:58:54Z")

</div>

Hi guys. Im trying to make something like this [https://youtu.be/lPdVyq9J138?t=21s](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.

---

<div class="post-metadata">

**Author:** ![Mosel3y](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mosel3y](https://forums.unrealengine.com/u/Mosel3y)\
**Post date:** [March 13, 2015, 9:58am UTC](https://forums.unrealengine.com/t/how-can-i-make-this-type-of-magnetism-grabbing-something/24063/2 "2015-03-13T09:58:22Z")

</div>

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

 ![t4PFyQY.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/9/3/93bb42a11e1f9b03b14925b7cca705d4fbd3961c.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](https://d3kjluh73b9h9o.cloudfront.net/original/3X/4/7/47e81ef292bc7679ce2d63bf0f9d440500227a3c.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…

---

<div class="post-metadata">

**Author:** ![ULLS](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ULLS](https://forums.unrealengine.com/u/ULLS)\
**Post date:** [March 13, 2015, 11:09am UTC](https://forums.unrealengine.com/t/how-can-i-make-this-type-of-magnetism-grabbing-something/24063/3 "2015-03-13T11:09:04Z")

</div>

[Physics handle](https://docs.unrealengine.com/latest/INT/BlueprintAPI/Physics/Components/PhysicsHandle/index.html) 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.

---

<div class="post-metadata">

**Author:** ![ULLS](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ULLS](https://forums.unrealengine.com/u/ULLS)\
**Post date:** [March 13, 2015, 11:28am UTC](https://forums.unrealengine.com/t/how-can-i-make-this-type-of-magnetism-grabbing-something/24063/4 "2015-03-13T11:28:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Aenopix](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Aenopix](https://forums.unrealengine.com/u/Aenopix)\
**Post date:** [March 14, 2015, 5:54pm UTC](https://forums.unrealengine.com/t/how-can-i-make-this-type-of-magnetism-grabbing-something/24063/5 "2015-03-14T17:54:51Z")

</div>

Hi again, thanks for appointing me to use physics handle, i did this tutorial [https://wiki.unrealengine.com/Pick\_Up\_Physics\_Object\_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.

 ![test.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/5/0/a50b3e2c76be58c9b90d9c890fccb722ca2ac85d.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

---

<div class="post-metadata">

**Author:** ![Aenopix](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Aenopix](https://forums.unrealengine.com/u/Aenopix)\
**Post date:** [March 15, 2015, 9:08pm UTC](https://forums.unrealengine.com/t/how-can-i-make-this-type-of-magnetism-grabbing-something/24063/6 "2015-03-15T21:08:10Z")

</div>

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](https://d3kjluh73b9h9o.cloudfront.net/original/3X/e/c/ec174081c35623fdce22f125897ecda842a9d9e2.png)  
 ![Capture2.PNG](https://d3kjluh73b9h9o.cloudfront.net/original/3X/a/4/a4141d6038a8c0421e8a3fa4c8797cb7867ff1da.png)  
 ![Capture1.PNG](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/b/3/9b3d481befef80ead090acec52f7261f06cd64f2.png)

Thanks

---

<div class="post-metadata">

**Author:** ![ULLS](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ULLS](https://forums.unrealengine.com/u/ULLS)\
**Post date:** [March 16, 2015, 10:19am UTC](https://forums.unrealengine.com/t/how-can-i-make-this-type-of-magnetism-grabbing-something/24063/7 "2015-03-16T10:19:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Aenopix](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Aenopix](https://forums.unrealengine.com/u/Aenopix)\
**Post date:** [March 17, 2015, 7:23pm UTC](https://forums.unrealengine.com/t/how-can-i-make-this-type-of-magnetism-grabbing-something/24063/8 "2015-03-17T19:23:35Z")

</div>

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.
