Material challenge: Morphing material based on velocity

Hello everyone,

I’ve been working a ton on a project with my brother (we’ll get a website and WIP post up in a couple of weeks, probably after exams :p) and I’ve reached my first major skill hurdle when it comes to materials.
So far every material we’ve needed has been very simple in nature, since the visual style in itself is cartoony, though this one is a bit different.

What I’m trying to achieve is a sphere that is squished and wobbles when it bounces and flies, imagine a waterballoon that doesn’t pop when it hits the ground. The problem is I have no idea where to start since my material experience is limited to the very basics. Any guidelines or if anyone want to help out creating this we would be most thankful! I’ve made a simple animation to show off the effect I want. I also thought about making it just a simple animated sprite but having it as a 3d object would look better I think. Maybe it shouldn’t be done with a material at all…

https://a.pomf.se/vhyunz.mp4

EDIT: maybe this is easier done with a mesh in cascade as morphing objects is relatively easy there.

depending on how accurate the squishing needs to be… basic world position offset will work. or if you are less mathematicall inclined static mesh morph targets could be another approach(technically similar, just userfriendly) Static Mesh Morph Targets | Unreal Engine Documentation

Hey divi thanks for the reply!

Doing something like WorldPositionOffset might work and will most likely create a nice wobbling effect, tho what I failed to mention is that this is for a projectile meant to be fired by the player. Now I’ve noticed something while experimenting with the basic Set 3D Scale in blueprints, and that is the axis for the static mesh roll along with the collision sphere, meaning if I base something on the hit normal the scale won’t always be the correct way. I’m not too sure how I could drive a material to change on impact, but wouldn’t it be the same? Meaning that even if it deformed it would have to know the normal of the plane it hit and the current rotation of the mesh itself. Maybe this problem is just way out of my league right now, but I really appreciate help!

Also, morph targets look interesting but it also looks like they’re for making set animations in a set way, so a projectile that could possibly be in every possible rotation and direction will render predetermined animations useless, no?

>>I’m not too sure how I could drive a material to change on impact, but wouldn’t it be the same? Meaning that even if it deformed it would have to know the normal of the plane it hit and the current rotation of the mesh itself.

I think currently you will have to use your blueprint to pass any information about its motion to the material.

All you need to store a variable for the position of the projectile at your previous frame and Subtract the current position from that. The result will be a motion vector. If you also store a variable for the heading last frame, you can tell when there was a collision in the material by doing dot product of the current and previous vector. You’d need some threshold value for whats enough of a course correction to be considered a bounce. In addition if you track previous speed you will know the acceleration of the object and do stuff like flatten on deceleration instead of lengthen.

You would subtract these vectors and create a material instance dynamic for the projectile and tell the material about them via the “Set VectorParameter” nodes.

Hi ryan
since this is my first advanced material I’m gonna have to look more into storing positions and the likes in the material, but what you say makes sense and I’ll try to see if I can’t figure it out. Is it possible though to just send information directly from the collision component, because then I could easily get both when it collides and the hitNormal and also possibly the acceleration? I’m real tired right now so my brain is kinda slow, I’ll come back tomorrow. Still thanks for the added input, I’m sure I’ll make it happen in the end and it will look awesome.

If your projectile exists beforehand as a blueprint component, you could try creating an event on your projectile “On Component Hit” and get events from that. But since most projectiles are created at spawn I am not sure how you could do it. But to get continuous acceleration info would still require sampling the position in the blueprint. You don’t have to do it every frame but if you do it less the data will be less accurate.

Alright! So thanks to your input I’ve gotten the basic concept to work! Though the road from here to something that looks like a blob of thick goo bouncing about is still long.

What I’ve done is I created a simple material that I can drive through blueprint code: http://i.imgur.com/msKJhbN.png

When the collision sphere triggers the EventHit, the MorphBall event is called which squishes the ball: http://i.imgur.com/2NDRzQA.png (I’m still working on a way to make it expand in the other two axis that is not the HitNormal.

Then I tried doing what you said about getting the direction vector from previous to current location and it “works”, however it looks very hacky (I’m not a very experienced programmer!). It also interferes with the squish and when it is nearing the end of its lifespan and rolling very slow it jitters extremely fast: http://i.imgur.com/RccdlOd.png

Thanks for all the help so far and if you have any further assistance I would be grateful! The main problem I have right now is finding a way of interpolating between squishes on collision and zooming when it’s flying through the air.