Download

Move Object Depending On Camera Angle

Hi, I’m trying to make it so I can drag items along the plane the camera is facing in the game world using mouse position, but I can’t figure it out, can anyone help please?

An example of this is the Cairn Stones in Assassin’s Creed Valhalla, where you can move a stone up, down, left, and right along the plane the camera’s facing How to do stack CAIRN stones at Heald Tor in HAMTUNSCIRE ► Assassin's Creed Valhalla - YouTube

So far I have a widget created that On Mouse Move gets the difference between the mouse’s current Screen Space Position, and the Last Screen Space Position, and want to use the Vector 2D variable calculated and add it to the grabbed actors current location, but at the correct angle to move it along the plane.

I hope I’m making sense, if not I can try to explain a bit more

See if this delivers:

  • you can have a plane to intersect with, its origin is where the pedestal is and the normal is camera dependent

  • we then trace from the camera towards the cursor projected into the world, eventually hitting that plane (it’s of infinite size, well almost)

  • this allows you to place something at that intersection:

Script (should, ideally, be in the Player Controller):

Notes:

  • do not use Set Actor Location for this - look into PhysicsHandle Component
  • the physics will not act right out of the box, on the contrary - it’ll be the very opposite of Zen
    – increase tensor scale, angular dampening and play with mass
    – crank up position & velocity solvers, maybe even enable CCD
    – look into physical materials, especially restitution
    – depenetration is another element - it controls how rapidly objects get ejected when their geometries intersect. Start around 100 and see how it behaves, adjust.

Tweaking will be required.


There might be a reasonable alternative to this using constraints.

when you pick the item you can:

  1. make a ‘find look at rotation’ from the object to the camera. This will give you an FRotator (orientation info). then you:

-Create a 'Scene object '(null transform object) in the objects position
-Set the world rotation of that ‘scene object’ with the rotator so this scene object has the right orientation regarding the camera.
-parent you original object to this scene object
-move the ‘scene object’ LOCALLY (add local offset) in the right local axes depending on your mouse movement.
-when you release the mouse you can unparent and reparent were needs, also unparent with keep world on transforms.

Hope it helps

Ah thank you, this works great! :smiley:

1 Like