# LineTrace puts a held object through the ground

**URL:** <https://forums.unrealengine.com/t/linetrace-puts-a-held-object-through-the-ground/442989>\
**Category:** World Creation\
**Tags:** socket-reference, physics-objects, unreal-engine, question\
**Created:** [February 8, 2019, 10:35pm UTC](https://forums.unrealengine.com/t/linetrace-puts-a-held-object-through-the-ground/442989 "2019-02-08T22:35:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![HawkTeevs](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HawkTeevs](https://forums.unrealengine.com/u/HawkTeevs)\
**Post date:** [February 8, 2019, 10:35pm UTC](https://forums.unrealengine.com/t/linetrace-puts-a-held-object-through-the-ground/442989/1 "2019-02-08T22:35:39Z")

</div>

I have created a system where when the player presses f, it will do a line trace and attach an object to a socket. I have another set of code to when the player right-clicks, it does another line trace and detaches it from the socket and teleports to the line trace end. It mostly works, but when I do it too close to me, either it will destroy the object or it will go through the ground. How do I fix this???

[??? - YouTube](https://youtu.be/MZzm4cBtbtQ) - Video showing the problem

Drop Object:

 ![267943-screenshot-66.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/a/b/eab60aea069401abacd5b4030fdd14e90e6bfe43.png)

Pick Up Object:

 ![267942-screenshot-68.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/7/5/675f33f327827bf1ccbb31ed52941935b259603b.png)

][3]

---

<div class="post-metadata">

**Author:** ![IndieGameCove](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@IndieGameCove](https://forums.unrealengine.com/u/IndieGameCove)\
**Post date:** [February 9, 2019, 5:41am UTC](https://forums.unrealengine.com/t/linetrace-puts-a-held-object-through-the-ground/442989/2 "2019-02-09T05:41:59Z")

</div>

on the release you would take the impact point and offset it so the box doesn’t teleport into the wall.

Off the top of my head I think the formula would be.  
impact point + (impact normal \* distance from wall/floor)

the “distance from wall/floor” is just a float variable that would give a bit of space from the floor on the release.

It won’t work in corners and certain cluttered spaces. you could run a check by doing something like making a box collision and sending that through to the expected release point get all overlaping actors if that array has a length greater than 0 change the crosshair color to red and not allow the player to release the the box until he turns to face a valid surface.

---

<div class="post-metadata">

**Author:** ![IndieGameCove](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@IndieGameCove](https://forums.unrealengine.com/u/IndieGameCove)\
**Post date:** [February 9, 2019, 5:44am UTC](https://forums.unrealengine.com/t/linetrace-puts-a-held-object-through-the-ground/442989/3 "2019-02-09T05:44:55Z")

</div>

I probably should have asked first but what do want to happen on the release? do you want it to teleport some distance, just want it to fall, would you prefer in lerps to a location?  
if you want the teleport to location behavior you have my answer above, I haven’t tested that specifically but I think it’ll work.

---

<div class="post-metadata">

**Author:** ![HawkTeevs](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HawkTeevs](https://forums.unrealengine.com/u/HawkTeevs)\
**Post date:** [February 11, 2019, 1:12am UTC](https://forums.unrealengine.com/t/linetrace-puts-a-held-object-through-the-ground/442989/4 "2019-02-11T01:12:41Z")

</div>

Here’s a video that is similar to what I want to do.

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/c/3/5c3152dc11a98ac1e52f0ee08cb119f8953d71f8.jpeg "Hello Neighbor prototype Inventory new features") ](https://www.youtube.com/watch?v=ENygHHVdc18)

---

<div class="post-metadata">

**Author:** ![HawkTeevs](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HawkTeevs](https://forums.unrealengine.com/u/HawkTeevs)\
**Post date:** [February 11, 2019, 1:20am UTC](https://forums.unrealengine.com/t/linetrace-puts-a-held-object-through-the-ground/442989/5 "2019-02-11T01:20:55Z")

</div>

Thanks, it worked!

---

<div class="post-metadata">

**Author:** ![HawkTeevs](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HawkTeevs](https://forums.unrealengine.com/u/HawkTeevs)\
**Post date:** [February 11, 2019, 1:35am UTC](https://forums.unrealengine.com/t/linetrace-puts-a-held-object-through-the-ground/442989/6 "2019-02-11T01:35:34Z")

</div>

Now that it works, when I right click in the air, it disappears. Is there a way to detect if the object is dropped in the air so that it just falls to the ground?

---

<div class="post-metadata">

**Author:** ![IndieGameCove](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@IndieGameCove](https://forums.unrealengine.com/u/IndieGameCove)\
**Post date:** [February 11, 2019, 2:42am UTC](https://forums.unrealengine.com/t/linetrace-puts-a-held-object-through-the-ground/442989/7 "2019-02-11T02:42:27Z")

</div>

yeah looks like you already have a branch node so just use it to check if the return value of the linetrace is false then if it is detach the actor and turn physics on so it falls to the ground.  
i think you would use the keep world for the transform rule not sure though.

just turn the physics off before you pick it up.  
you can look at the vr template if you want an example.

---

<div class="post-metadata">

**Author:** ![HawkTeevs](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HawkTeevs](https://forums.unrealengine.com/u/HawkTeevs)\
**Post date:** [February 11, 2019, 2:54am UTC](https://forums.unrealengine.com/t/linetrace-puts-a-held-object-through-the-ground/442989/8 "2019-02-11T02:54:04Z")

</div>

Yep that worked. Thanks

---

<div class="post-metadata">

**Author:** ![IndieGameCove](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@IndieGameCove](https://forums.unrealengine.com/u/IndieGameCove)\
**Post date:** [February 11, 2019, 8:56am UTC](https://forums.unrealengine.com/t/linetrace-puts-a-held-object-through-the-ground/442989/9 "2019-02-11T08:56:06Z")

</div>

sure thing
