Apply torque/rotational force to an object?

Hey guys, I’m making a vehicle and currently using SetAngles in a move hook to set the angles of an object to where the mouse is looking.
The issue with this is that SetAngles doesn’t check for collisions. When the vehicle is touching a part of the map or a prop, the vehicle glitches out and often pushes itself through the wall.
I figured one solution would be to set the rotational force of the object so that the entity will collide while it rotates. I know this is possible (perhaps not in lua, but possible) because that’s how the physgun works when you hold E while physgunning an object (it doesn’t just set the angles, it collides with objects)

Was wondering if anyone knows the lua binding for this, or if they can offer a better solution to stabilize the entity when it collides (it collides fine while moving in the worldspace, just not while rotating).

applyforceoffset is what you need.

[editline]1st February 2016[/editline]

or computeshadowcontrol

Shadow control works great, if maybe a little taxing to the server if you wanted 20-30 of these happening at once. Ignore the name of it; what it does is guides an entity via physics over specified parameters.

Foohy’s lua-generated rollercoaster addon on the workshop uses shadow control to smoothly guide rollercoaster cars with retained physics.

Just be aware that if it collides with something it will spazz around as physics force tries to pull it to the intended location; in your case, however, it sounds like the intended location/angles will always be very close by to the collision, so the added spazz stress should be very low.

You could also experiment with iterative TraceHull to find out what the last valid angle that doesn’t collide with the wall is.

computeshadowcontrol shouldn’t spaz. Turn down your maxangular and maxspeed.

Thanks for your responses guys, got it working pretty swell, only issue now is prediction.
Any idea how I might predict this stuff?
Might dissect that rollercoaster addon