Hi all, I’ve been trying to figure out how to click and move (drag) an actor in 3d space using C++.
My plan was to:
- Select object with click and update a pointer to point to the grabbed object. (this is working)
- In Tick method, move object to mouse location projected onto the floor.
- On click - release at mouse location.
However I have not been able to figure out how to translate mouse x,y to world space in the tick method in way that will work. (I suppose I could fire back down looking for impact position on selected actor and move it, but I feel this could fail if mouse moves to much in tick internal).
Looking for any pointers?
This is what I’m doing in the click method:
controller->DeprojectMousePositionToWorld(worldLoc, worldDirection);
FHitResult hitResult;
bool bHit = controller->GetHitResultUnderCursor(ECollisionChannel::ECC_GameTraceChannel1, false, hitResult);
if (bHit)
{
grabbedActor = hitResult.GetActor();
}
After a bit more playing around, I have come with this ‘hack’.
I have 2 trace channels (1 for objects that can be picked up, and 1 for the floor).
So in the Tick method, I search for a HitResult on the floor (using floor trace channel), and move the grabbed object to that location. This feels wrong, but its working for now.