Hey there, new hobby game dev here,
I am making a game in my free time to keep me busy and without going into to much detail, part of it involves placing an object in the scene wherever the mouse cursor is on the floor.
Currently I have a system in place where a line trace is projected from the camera to the mouse in world space, and then attempts to line trace again straight down to make sure that no objects are levitating. It will then do a check to make sure that the object is in view if placed in the hit location but that isn’t too relevant for the problem I’m trying to solve.
This system works pretty well except for one thing… objects can clip into walls, which I don’t want. I use a lerp and timeline to smoothly move the object to wherever the mouse moves but the object isn’t stopped once collision is made. I use the sweep option on Set Actor Location but that didn’t do anything, assuming it is because I don’t simulate physics in the object.
To try and fix this, I turned on simulate physics, but the actor didn’t even move to the line traces hit location, probably because I initially spawned it at the world origin and it was getting blocked by walls when trying to move to the mouse location. To combat this, I set the initial spawn location to be at the mouse location, but the actor still refuses to move to the line trace after this. However when I click to spawn the actor regardless, it does spawn at the mouse location but does something weird. It just starts floating in a random direction across the floor and spinning in a circle for some reason…
My question is, does anyone have an idea on how I prevent clipping WITHOUT simulating physics, or if that’s not possible (which wouldn’t surprise me), how could I get around this weird issue of it just levitating away, and the preview not properly updating?
Thanks for help in advance!
EDIT: I have done more research and found that Simulate Physics shouldn’t be required to check collision, so I have turned that off again for now. I checked the sweep option properly and it says that only the root component is checked for collision, which I guess means that I would need to have the mesh as the root component. This is an issue though as the objects that can be spawned are all child classes so the root component is unchangeable… any ideas on how I can get around this? Or is there any better way of going about preventing the clipping? Now that I think about it, the objects could get stuck really easily during movement if it was stopped by sweeps…