bend static mesh (tree) to the direction of hit

Hi,
I have to ask about a strange result I get when I try to make a static mesh (a tree in my case) to bend to the direction of a hit it receives.
My approach is to use a timeline for the animation. When the character traces the tree, I calcultate the direction it should bend as follows:
(Location - Trace Start) from the hit, normalize it and then convert it to local space (by using the Inverse Transform Direction).
Then the timeline starts and as it plays a float curve (which starts at 0 goes up to 15 and ends at 0) is multiplied by the x and y of the hit direction vector and the result is passed to the static mesh relative rotation.

The problem is that from some directions the mesh does not bend. Do you have any idea of what’s wrong or any other suggestion how can I do it?

  • whose transform is used here?
  • is there a reason for the inversion? Is it because you’d like to apply the bend to a tree’s component only rather than to the entire tree actor?

The transform is of the static mesh.
The tree is not an actor, it’s just an instanced static mesh

1 Like

There should be no need to inverse the transform. I’d keep it all in world space:

This should :crossed_fingers: rotate an instance by 5 degrees away from the player. Do tell if that works for you.


If this is a tree, I’d just make sure that the pivot is where the tree’s roots would be rather than in the centre of the mesh.

It works for a single bend. But as long as I pass the update in a timeline (to have animation) it doesn’t work.
The problem with your solution (which does not apply to the static mesh but to the instance) may be that I use a dynamic instance spawner for the instances (a third party plugin) which may use the instances differently.

In my initial implementation, when the player hits the tree, the spawner removes the instance and replaces it with an indipendant static mesh component. In that case, I cannot use the update instance node but I have to change the rotation of the mesh itself. I will try your solution with the mesh and return.

I wonder if there is a way to animate the rotation of the instance (bend against the player at a certain angle and then return to initial rotation) without the use of a timeline.

So I took it for a spin, bending randomly rotated “trees” away from the player:

Something I discovered after actually testing it - we need to exclude Z from the calculation:

Hope it helps.


It should not matter whether this is an ISM Instance or a Static Mesh; a transform is a transform.

I wonder if there is a way to animate the rotation of the instance (bend against the player at a certain angle and then return to initial rotation) without the use of a timeline.

Like chopping the tree and it springs back, providing feedback to the player? If you’re replacing instances with static meshes:

  • extend the SM
  • put a timer inside
  • use the timer’s progress to lerp between rotations, I’d have the timer sample a curve so you have a mini timeline with minimum overhead

But this could be driven by the player’s timeline, ofc. If you’re worried about cluttering the player class with too many of those, consider reusing the same TL for many animations - TLs can load curves dynamically. How to approach it depends on the scope, ofc.

Thanks for the insights!
I did the right bending after replacing the instances with static meshes and using your world calculation.

As for the animation part:
I suppose I cannot extend the Static Mesh via blueprints, right (i don’t know C++)?
I also suppose there is no way to use some form of looping inside a function (for example to lerp between the rotators), right?

You can:

Most components can be handled like this.

looping inside a function

You can run loops inside functions but you probably have something else / specific on your mind - something latent - not a function territory.

Fantastic!
Yes I have a latent loop in my mind.
And, for anybody interested there is a fantastic plugin (TweenMaker) which does exactly that!
Animates any actor or scene component from anywhere (even inside functions).
So, I keep your calculations for the end rotation but I use the plugin to animate the static mesh from inside my function.

Thanks again

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.