I trying to apply a directional impulse using Add impulse at location based on the facing of my player controller or pawn, what I’m trying to do is push a tree over in the facing direction, i would like to then use this later on for cutting down trees, any help would be great, I’m new to blueprint but have used the unreal editor a lot so some guidance is welcome.
First enable physics for tree.
For this make sure tree has collision, you probably need to overide its mass and enter of mass (all this is in mesh properties).
To test if physics works, enable gravity tree should fall.
When all that work, create blueprint that will have tree mesh.
Now you need trigger volume that checks if player is nearby. You can check that in event “begin overlap” of trigger volume.
Now making tree fall. First make it not fall until its time. Set default settings of tree to no physics. Not sure here what would do best, probably turning off physics, then enabling it in player overlap is easiest.
When you overlap trigger, turn tree physics on, and add impulse. Remember to check “change velocity”. If you dont want to do it with change velocity you need add impulse from event tick for several ticks.
Or just offset center of mass for tree, it will fall down self.
For simulating different tree fall directions you need to do some smoke and mirrors trick. (i think this will be best solution for you, but first play with above as its easier to implement):
create blueprint that has invisible collision mesh That is asymmetric (has one side bigger, like added asymmetrical box on top of long symmetric box), use this for all trees
that collision box will be your physics tree, use gravity method from above part to make it fall.
then add static mesh that is purely visual, this should have mesh without collision or physics, that roughly fits collision mesh
Finally to make tree fall where you want:
find direction that player is coming from, you can do it on begin overlap, find vector from tree to player, use look at rotation to find rotation.
rotate collision mesh in way that asymmetrical mesh is facing directiontree should fall.
What i have setup at the moment is a actor BP with two mesh components, two collision boxes and 8 physics thrusters, I’m using “BeiginOverlap” on the one of the collision boxes this triggers enable physics on the tree then it uses a random integer to pull a random thruster which then pushing the tree over in a random direction, the tree then falls and gets visibility and collision disabled then it uses SetRelativeLocationAndRotation to get put back to its starting position and gets toggled visible again, I would like to tree to get pushed over in the opposite direction of impact/overlap.
The easiest way I have been able to do something similar is this:
Get your player location and get the tree location. Subtract the two vectors to get a line between the two. Use a normalize node on the result so the impulse has a force of 1 in the direction you want. Then multiply it by a float it int and plug that into the add impulse node.