Jump to content

  • Log In with Google      Sign In   
  • Create Account

how to simulate plants as Trine 2 performs


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 tracegame   Members   -  Reputation: 134

Like
0Likes
Like

Posted 26 December 2012 - 08:13 AM

Trine 2 is great,the image,the physic.and i can't help asking.

 

how to achieve that physical plant.

 

when i step over and at the edge,they just bend.when you walk away,they turn back to normal.

 

how can i do such thing?is it possible to simulate in box2d?

 

is it some kind of rigid body or soft body or what?



Sponsor:

#2 Kaptein   Prime Members   -  Reputation: 2165

Like
0Likes
Like

Posted 26 December 2012 - 07:09 PM

i probably wouldn't go that far with plants, unless they are complex plants
it's more likely just a classic case of stretching, scaling and skewering
you can do all of this with matrix ops, or simply moving the vertices of a quad
note that this will distort the texture!

i imagine that in trine, it's alot more involved than that
some game companies animate plant movement for common plants, since that always gives the best result
however, it should be enough to just modulate the plant vertex positions a little

a basic formula would be:
const float MAX = ...
const float POWER = ...

x = 1.0 - min(MAX, distance(player, plant)) / MAX // get euclidian distance
z = (plant.x - player.x) / MAX // get signed X-distance
vertex.top_left += x * z * POWER
vertex.top_right += x * z * POWER

in a shader, you can easily find the top vertices in one go by multiplying with .t, assuming t == 1 at the top of the texture
like this:
vertex.x += x * z * POWER * texCoord.t;

note that 1D distance is a simple calculation: abs(x1 - x2)
but for it to be signed, lose the abs() and you can tell which side the player is on!

#3 tracegame   Members   -  Reputation: 134

Like
0Likes
Like

Posted 26 December 2012 - 10:08 PM

thank you Kaptein,that's a nice solution,and more easy to do. laugh.png






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS