- Home /
Bend 3d object (Mesh) at Runtime
Hi, so I am making a game that will change some things based on the overall speed of the game and player charachter (don't want to get in to much datails) Though something that can help you picture what i am trying to achive is that this game is subway surfers style, if you've ever played it (which i doubt that you haven't).
One of the things that will change is the player path and it will change from this: To something like this: ( Not the same scalling its just somthing i made quickly for the sake of demonstration like i dont want it to strech as much ) Basiclly I want to bend the platform at runtime.
How in the world can I do that. AnyThing can help!!
Answer by OnEd0t · May 04, 2020 at 07:35 PM
So, After a week of searching an scouting the internet for an easy simple way to bend the damn mesh at Runtime, I finally found an answer, But not something that I Personally would enjoy making. Simply you CAN do it, but:
You would have to create the mesh yourself in unity itself, as in assign all the vertecies and triangles and have to work all of that in vectors. it sounds more complicated than it actually is, but this is way to much for what I want to achive + I've givin up on the idea of having a bent mesh in the game.
Still if you have a way post it here in the thread or somewhere on the internet, so that somebody else can find the answer more easily.
Pretty lame answer but sorry, that's what I have.
The link I posted to your question shows you the Unity functions and example on how to create a new or edit an existing mesh. A mesh is just a set of points that describe an object. Triangles are logical groupings of those mesh points to tell the graphics renderer where to paint. A triangle's 'normal' is the side of the triangle that will be painted, the other side will not and would be see-through. The physics engine uses the meshes to find collisions, which is how your player would be able to walk on the mesh. Each point on the mesh is defined by its local x, y, and z coordinates. Local coordinates are ones where (0, 0, 0) is the center of your mesh when you build it in, for example, Blender, and import to Unity. For mesh editing, if you load a mesh, the points are referred to as vertices. You can cycle through each 'vertice' and change the x, y, and z location any way you want. If you had a mesh of a plank, and wanted to bend it, you could write some code to:
1) find the left-most and right-most vertices on the plank
2) calculate the distance between those two vertices, then divide by two
3) iterate through each vertice and change its Y coordinate proportionally to the value you got from 2). Write the equation such that the larger the difference between the vertice's X coordinate and the value from 2), the larger deflection you apply to the Y coordinate of that vertice.
Singular for vertices is vertex. Also be $$anonymous$$dful of which dimension in your local mesh corresponds to X, Y, and Z.
Answer by Bunny83 · May 03, 2020 at 10:31 AM
You mean something like this:
I mean... i have thought of making it an illusion, but i don't think that it work for my use here since A) i am not bending on the Z Axis I am bending on the X Axis and an illusion won't work simply because i am bending quite a lot actually, see the main game character isn't a human, its a space ship and ins$$anonymous$$d of flying linearly or like in a straight line across the X Axis, the path will start curving (in a parabolic shape cuz the ship can already fly across a parabola) based on the speed of the ship and the overall game, so as it gets faster the path will start curving, and when i say curving, it means A lot of curving and an illousion isn't going to cut it. B) I am bending for the sake of making the game harder in diffeculity not for looks or aesthetics (hence the extreme bend)
I just want to bend the mesh in runtime
though if its the only option i guess i'll have to start learing everything about shaders.