Brainstorming: Top-Down Water Movement?
by Chase Webb · in Torque 2D Beginner · 05/14/2013 (6:01 am) · 11 replies
Hey all. I'm making excellent progress in working with the engine lately! I'm not directly working on this yet, but I'm curious how to tackle it. Basically, I want to apply a slowdown effect to everything, as if it were moving through water. Sort of like how applying gravity to something pulls it to the bottom of the screen (or wherever you set it to) and eventually brings it to a stop, but from a top-down perspective. I'm hoping there's something in the physics system that I don't know about that can handle this, and I don't have to worry about fancy functions to simulate it.
Anyone have any tips?
Anyone have any tips?
#2
It's really a matter of taste and how you want your objects to behave so be sure to experiment with as many solutions as possible!
Two things you can try :
1 - Damping
As soon as an object is known to be underwater, you can modify its LinearDamping property so that every physics-induced movement is muted a bit.
Where scale should a value be between 0 (non-dampened) and 1 (full damping)
Note that you can also add Damping to Joints, not sure if that will be necessary in your scenario.
2 - Gravity Scale
This property can be set per-object and affects how the Scene gravity will influence the object.
Also from 0 to 1.
You know we'll want to see a video of the solution you find :)
05/14/2013 (10:15 am)
Just know that you can change any physical property of the objects and see their physical response change instantly. As long as you keep tabs on all values you're modifying in real-time, you should obtain the expected result pretty fast!It's really a matter of taste and how you want your objects to behave so be sure to experiment with as many solutions as possible!
Two things you can try :
1 - Damping
As soon as an object is known to be underwater, you can modify its LinearDamping property so that every physics-induced movement is muted a bit.
SceneObject.setLinearDamping(%scale);
Where scale should a value be between 0 (non-dampened) and 1 (full damping)
Note that you can also add Damping to Joints, not sure if that will be necessary in your scenario.
2 - Gravity Scale
This property can be set per-object and affects how the Scene gravity will influence the object.
SceneObject.setGravityScale(%scale)
Also from 0 to 1.
You know we'll want to see a video of the solution you find :)
#3
05/14/2013 (2:58 pm)
Damping, that's what it was. There's also a setAngularDamping if you want to affect rotation as well.
#4
05/15/2013 (5:57 am)
Thanks everyone! setLinearDamping() did EXACTLY what I had hoped for! I'll put up a comparison video this weekend (or whenever I get the time).
#5
05/17/2013 (4:39 am)
When the video finishes processing you can find the results/examples of the LinearDamping here: http://www.youtube.com/watch?v=BiI7bw110nU
#6
05/17/2013 (8:02 am)
Dude - you made it private....
#7
05/18/2013 (2:26 am)
Oops! Fixed now!
#8
Pretty cool video. I made your link live.
05/18/2013 (7:08 am)
www.youtube.com/watch?v=BiI7bw110nUPretty cool video. I made your link live.
#9
I like your water effect.
Can you give any tips of show an example of how you created the background water effect? The only water example is the sidescrolling one, how did you adapt it to top-down view?
05/18/2013 (10:24 am)
Hi Chase,I like your water effect.
Can you give any tips of show an example of how you created the background water effect? The only water example is the sidescrolling one, how did you adapt it to top-down view?
#10
05/18/2013 (5:18 pm)
Well the rock background is on Layer 31 as a non-moving scroller, while the water is a single image scroller with randomized direction. You only see it going in one direction in the video clips, but if I set my randomization seed to use the clock then every time I open the prototype it is flowing in a new direction. I then did a little math to set the gravity so it is always pulling in the direction of the water flow. Here's a clip of my code:// Create the sprite.
%waves = new Scroller();
%waves.setDefaultRestitution(1);
// Set the sprite as "static" so it is not affected by gravity.
%waves.setBodyType( static );
%waves.Position = "0 0";
%waves.Size = "200";
%waves.SceneLayer = 30;
%waves.Image = "MyModule:Tilewater";
// Repeat the image.
%waves.RepeatX = 10;
%waves.RepeatY = 10;
%waves.wavepullX = getRandom(-4,4);
%waves.wavepullY = getRandom(-4,4);
// Scroll the image.
%waves.ScrollX = %waves.wavepullX;
%waves.ScrollY = %waves.wavepullY;
MyScene.setGravity( -%waves.wavepullX, -%waves.wavepullY );
#11
05/18/2013 (10:04 pm)
That is awesome Chase. My water scene looks so much better now.
Torque Owner Daniel Buckmaster
T3D Steering Committee
I'm pretty sure the physics system has a built-in concept of drag, actually - maybe have a search and see if you can modify it in real-time (I'm sure you'll be able to).