Hello everyone There is such a problem - I have a bottle sprite and a sprite showing the water level in this bottle. But, as you understand, if you start rotating the bottle, the level will remain the same. How to make the water rotate realistically? (was always downstairs)
As far as I understand, you probably need a shader, but I'm not strong at all.
I tried to make water in small circles with physics, but it works unstable and the balls periodically slip through the wall.
What I need
What I have
So long as you don't care about liquid sloshing and the volume staying consistent you can use a simple sprite mask.
Note that the box collider isn't necessary, it was just added to illustrate the underlying sprite size.
Related
Hi I'am new to Unity and I was trying to implement a game using tetris blocks.
The game's goal is to build the highest tower before it collapses. However there is a problem in my implementation which is seen in the picture below.
I achieve the building a tower task by activating the rigidbody gravityscale when it collides with something. With that way it can collapse after touching somewhere not before. But I want to have the flexibility of some collisions. In the situation seen in the picture below, that 'T' block will collide with the point in the red circle before landing safely and gravityscale of the rigidbody will be set. So it will drop but I don't want it to happen becasue the collision area is too small. I want to make it land safely with some flexibility.
I tried to make colliders' size 0.9 but that just disrupts the scale of the world.
Can I do something like this :
If collision happens, check collision area and if the area is lower than lets say 0.1, do not trigger rigidbody gravityscale.
what about using capsulle collider 2D with small radius?
so I have this game in which I have destructible terrain. my setup is that when terrain is destroyed a part of the terrain texture is made transparent, to act as a crater. after any kind of change takes place, I delete the polygon collider on the texture for the terrain and create a new one in order to recalculate the terrain, but obviously this is very taxing on processing power. is there a way to reset the polygon collider without having to do this?
in addition, the polygon collider is not very accurate and I've been told that pixel perfect collision is not possible in unity, but I hold out hope. is there a way to increase the accuracy at least?
here is an example of my problem:
Collider recalculation is expensive, and there's no way around it in Unity, you can't even do it asynchronously.
It depends on your exact situation, but for a Worms-type game with dynamic terrain destruction, I wouldn't use polygonal colliders/Unity physics engine at all.
I'd create my own pixel-perfect collision system that would rely only on the underlying terrain texture.
You already have the terrain data, checking for collisions could be done with Bresenham's algorithm.
Here's a tutorial: http://gamedevelopment.tutsplus.com/tutorials/coding-destructible-pixel-terrain-how-to-make-everything-explode--gamedev-45
I would recommend setting up cluster-based colliders in this case. How do you calculate the area of texture that becomes transparent? If it has a fixed size, you can create a one big collider, which consists of many smaller (hexagon shaped maybe?) sized colliders, whose size equals to the area of texture made transparent.
After you make the texture transparent, you simply destroy the cluster. Though you would have to make the hex(if this shape you choose) grid for every map.
This would be harder to implement in procedurally-generated maps, but it is still possible, as there are no dynamic colliders at the moment.
How can I make a big island (open world style) with water surrounding it?
I don't think that adding a big water prefab (standard asset) to the center of the island with big scales is a good idea, because it would be always rendered to the user which uses high amount of resources.
Should I add more, different sized water prefabs to the shore?
Which one is a better practice?
A large water object placed under land won't be frustrum culled because some part of it exists in the camera frustrum (unless you look straight up). Because of this it will be part of the back-to-front drawing pipeline and thus is not efficient. This is the danger of using over-sized polygons and/or extremely large childless objects.
If the water consisted of a individual objects; each with its prefab and mesh; then objects "off screen" could be trivially culled. Therefore you should use multiple prefabs of sufficient size so as to cullable at times via the frustrum.
Use the water asset that comes with standard assets, make it large and just create your island ontop of it. Unity also only renders what the player can see in the frustum camera, so it wont render all the water (it used to as it was a bug but its been fixed now i think). You can also look into occlusion culling
What's the best method for pulling back to show more of a view in a 2D OpenGL iPhone game? For instance, in Tiny Wings, when the bird flies toward the top of the screen the bird and the scenery pull back to simulate the bird going higher in the sky. Would this effect be better achieved by scaling all the sprites proportionally, or by using glOrthof? In any case, I'm assuming that the zoom-out factor is inversely proportional to the player's y position.
You almost certainly want to use glOrthof so all you're changing is how the camera sees the scene. This avoids recomputing all the normals and such in the scene, saving quite a bit of work. It's also easier for you to implement.
Hello everyone I an very new to cocos2d, so I apologize if this is a simple question. I would like to create to sprites that collide when they hit each other.
For instance, one sprite, spriteA, is in a fixed position on the screen. And another sprite, spriteB, is moving around the screen. SpriteB will collide with spriteA. If that doesn't make sense or you don't understand it, tell me and I will elaborate further. Any help is appreciated. Thank YOU!
Try using Chipmunk or Box2d physics systems. These are included with Cocos2d and work by having a physics simulation that updates with every time the graphics change on screen.
The physics simulation will tell you if two objects are overlapping, and will provide physical attributes like weight, slipperiness (friction), speed and direction, which creates reactions like bouncing, sliding, realistic loss of speed and changes of direction on impact.
If you are new to physics simulation, here's a 30 second run down:
Create "bodies" in the physics simulation that represent each graphical sprite
Bodies are usually defined more simply than their graphical counterparts, like a circle, square or simple polygon shape
In order to update the graphics on the screen accurately, first you establish a pixels to meters ratio. Meters are notional (i.e. made up) measurement that is used in the physics sim
Each time the physics simulation "ticks", you update the graphics on screen accordingly
So if a body in the physics sim moves 1 meter, you might transform the pixel sprite 32 pixels
Here's a good tute on collision detection using Box2d.
http://www.raywenderlich.com/606/how-to-use-box2d-for-just-collision-detection-with-cocos2d-iphone
enjoy
Its actually very simple:
Just schedule a timer: [self schedule:#selector(checkForCollision:)];
Specify the method: - (void)checkForCollision:(ccTime)dt {}
In the curly braces, make CGRects for each sprite using CGRectMake.
Then in the same method, just call: if (CGRectIntersectsRect) {}
That easy!
Well technically speaking when the 2 sprites interact, or share at least one common point, then they are colliding. I'm a little confused by your question. Are you asking for direction on how to make the sprite move on screen, or are you asking how to handle the actual collision(such as calling a method if they collide)?