The system I have set up is the player draws a line trace from the crosshair (middle of the screen) to find draggable objects. Clicking and holding the action button (left mouse button) would allow the player to manipulate the object’s location, ‘dragging’ it around the level. Once releasing the button, the object is placed down on the ground.
(note: it makes a little displacement in the z direction and ‘jumps up’ when interacted with. Thats done on purpose).
Here are the few issues I’m having. The first line trace just checks if it intersects with a draggable object. Holding down the action button while looking at the object in question would fire a second line trace, ignoring the interacted object. It hits the ground and gives a ‘hover’ and a ‘placement’ location. When dragging the object around, its setting the object’s location to the ‘hover’ location. When the player eventually releases the action button to place the object down, the object is set to the ‘placement’ location.
When pressing the button down, the object ‘snaps’ to the hover location. When the object is placed down after releasing the button, the object sinks a bit into the ground.
The obvious reason is because I’m manipulating the scene root of the object, setting its location (I’m assuming world location?) to the ‘hover’ location, thus the ‘snap’ it does when interacted with. And it sinks in the ground because the root is then set to the ‘placement’ location.
I’m not familiar enough with transforms and all to figure out a way to allow the player to drag the object from any point on the object, as well as to place it on the ground without having it sink.
Any advice on how this is usually done?
It’s much easier if you make interactive objects into blueprints. That way, you can set it so that putting down doesn’t need any transform ( because the root of the BP is the ground ), and the BP can also manage it’s own pickup / put down process.
Well the pick up and drop is within the interactive object. The player just shoots a line trace to identify the interactive objects, but once pressing or releasing the action button, its the interactive object that contains the logic of how its being displaced and dropped.
I’m setting the WorldLocation or SetActorLocation of the object when dragging it around or dropping it.
Should I have tackled that differently? Or is this not what you meant?
the Interactive object bp does have a scene root and a static mesh component. When im setting its location for dragging or placing, I’m manipulating the scene root location to be the hit result location of the line trace for both dragging the object around and for placing it.
How would you change it?
Yes, change the way you’re doing that.
You can either make the interactive object somehow contain the mesh ( or whatever ) in such a way, that using it’s ( the interactive object ) default pivot point works for putting something down.
Or move that logic into the item contained in the interactive object, so it knows how to put itself down correctly.
So, the interactive object is a BP, does it just refer to a mesh?
Well, something needs to change on a per object basis, so that part needs to be in the ‘descendant’. I think that’s your problem at the moment, you’re trying to put item specific stuff in the parent.
You either need to do something in every child so you can always use the same pivot point in the parent. A scene component would do the trick. You can have it in the parent, but move it to the correct place in the child.
I just tried it, it works. So you just have a scene component in the parent, which you can position in the child. All the parent has to do is put the scene component on the ground / surface.
So is the solution to place the root in such a way that the static mesh would be on top of it? so when placing the root down on the ground, the mesh would always be on top?
What about grabbing the object from any point on the mesh and not have it snap ?
This is the code inside the interactive object
edit: forgot one function
What does you grab code look like?