So here’s my situation. I’m working on a very flexible drop-in-ready system for cutting trees (could be statically placed or instanced foliage) that eventually I plan on releasing. Right now I’m trying to work out how to tell when the tree has crashed into the ground. The method I’m currently using is to place a scene component above the top of the tree, parented to the tree. After it starts falling, I track the Z movement of that component, with a user defined amount of initial ticks to ignore, as it sometimes wobbles a little before consistently falling. After the initial ticks have passed, the impact is then determined by the point at which the next Z value is higher than the previous one, aka the tree has bounced, at which point I stop the creaking and trigger the crashing effect. On mostly flat terrain this triggers correctly about 80% of the time, which is not reliable enough.
So is there any better way to reliably detect this impact?
I am also looking for a good way to stop or at least significantly reduce the wild spinning on the local Z axis that happens about 50% of the time as it hits the ground.
Last, how, in blueprints, can I disable the collision between an object and the player only. I have no problems setting physics enabled/disabled, but can’t seem to figure out how to set the individual collision options like you can from the editor, but once it has started to fall I don’t want it to collide with the player anymore.
For setting up collision parameters, i think theres a struct for that which you can plug into a collision properties node.
As for falling trees, do a (several?) ray cast to the ground where you spawn a trigger volume that checks for an overlap event to tell your tree to fire the crash effect?
Thanks for responding, I will look into the collision properties, however I think you misunderstood my main issue. The spawning is not a problem, for that piece, I am doing a trace and then spawning the mesh in the exact same position as the hit result. The Z tracking, and resulting problem, comes in to play when I fell the tree afterwards. That is the action for which I am trying to essentially determine as accurately as possible when the tree has fallen, so that I can trigger the impact sound and camera shake. This is where my current method is trying to detect when the tree has “bounced” as it hits the ground. Every method I’ve thought of becomes unreliable if the terrain around the tree is not just so. For example, if the tree falls over a rock and see-saw’s before coming to rest, or falls in a way that causes it not to bounce at all.
Both H1Z1 and 7 Days to Die seem to be able to do this reliably, with H1Z1 having the effect I am mostly trying to emulate. I do my cast, replace the instance with a BP version, wait for it to be cut down, enable physics, start playing the sound of the tree falling, wait for it to impact the ground (or whatever happens to be in its path), stop the falling sound and play the crashing sound, start a destruction timer, and then drop it through the ground before removing it from the game. All of these pieces are working great except the impact detection.
Other methods I’ve visited and thrown out:
Compare the height of the point I am tracking with the origin point (which is at bottom center), trigger impact when they pass each other: Required perfectly flat terrain with no obstructions
Average the rotation values of the X and Y axis and trigger impact when the difference in rotation delta drops below a defined threshold: Not even close to reliable
Trace down from the tracking point above the center of the trunk, triggering impact when it is within a defined number of units from the ground: Also unreliable due to terrain variation and objects that may get in the way
Instead of a simple point, use a collision sphere and trigger impact on overlap: This could work if every tree were perfectly straight and had the same diameter, but without that consistency it becomes unreliable, also still unreliable if it fell in such a way that the top did not reach the ground.
Of all the methods I’ve tried, detecting the bounce seems to be the most promising, but still with its faults. The best workaround I’ve got is to just accept that it will not always trigger the impact, and run the destruction nodes after a set amount of time has passed with no impact. I am not very satisfied with that acceptance though.
I think you misunderstand my ray cast idea. Its basically a method to spawn trigger volumes (how many is a performance v precision thing) on an uneven surface beneath the felled tree, each with the ability to detect an overlap event with your tree actor.
Basically do a conical cast (or multiple line casts forming a cone) from an “apex” point down to the ground, spawning a trigger volume at point of impact which contains your trigger for the crash effect.
You can even have it only trigger the crash (or trigger crashes of varying intensity, even multiple crashes if the tree falls in a stepwise fashion for example) if the trigger volume is a certain distance away from the origin (or in the case of a stepwise crash, from the previous trigger volume that triggered and event. This also prevents retriggering of the crash effect in case multiple volumes are overlapped) to add a bit more realism to it.
So it took some work, but I finally got something working based off of your suggestion, changing a few things. Instead of doing a conical cast and placing triggers 360 degrees around (I think that’s what you meant by that), I opted to add a Spline matching the height of the mesh bounds, with a configurable number of sections. The duration of the spline get set to the section count, and then at each whole number in the spline time, I cast straight down and move a trigger sphere along the ground. I need to tune it a little and put in a fall-back, but right now I have it execute the crash when either the outer trigger is overlapped, or at least half of the sections have overlapped.
I also changed the collision mesh of the tree to be a rectangle rather than a 1:1 of the trunk, and that significantly reduced the spinning.
For anyone stumbling on this thread that might try to optimize the original idea as I did, I thought I would be smart at first and rather than bother with the tracing, I tried spawning collision spheres at the trace start points, and just check for overlap with the ground. But after much fighting finally came to the conclusion that you can’t use overlap with landscape, so don’t do that.
Good going mate. Silly me, forgetting theres such a thing as world Z so you can always cast straight down. Ill have to keep your solution in the back pocket now :).