LineTrace puts a held object through the ground

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 - Video showing the problem

Drop Object:

Pick Up Object:

][3]

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.

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.

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

Thanks, it worked!

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?

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.

Yep that worked. Thanks

sure thing