How to access the 2D mesh of a sprite by code then change the shape of the sprite?
I want to make a game similar to Agario
I just was wondering how to achieve this jelly form when touching objects either by collisions or triggers ?
I would like to see more answers.
Scaling won't get you the kind of deformations you want. Coding deformations the way agar.io does it from scratch is quite difficult. I can see multiple ways of doing this, so I'm going to list them from most recommended to least recommended:
Start with a flat 3D mesh and render your sprite on it as a texture so you basically get a billboard. Then use collision events to get the contact points and use math to figure out how to move the mesh's vertices in response to the contact. You can see someone achieving that effect here and you can see a full blown tutorial for a sphere here, a highly recommended read. Your idea with getting the line from the center of the circle via the contact position and decreasing its length is sound, though the implementation is a bit more complex than that if you want it to behave like agar.io.
Get Anima2D, a free asset that can among other things convert sprites to meshes. Then again use collision events to get the contact points and distort the mesh.
Use Anima2D or a different asset with equivalent capabilities and figure out how to use 2D bones in order to get something like agar.io's effect. You could also try 3D bones on a plane/billboard mesh.
Send the collision data to a vertex shader that is programmed to deform the thing it's rendering.
you can contact gameobjects with Trigger function. That function is working automatically with GameObject's tag names. Here is how you can get Triger function
And also you can change size of GameObjects when they touch each other
More info about scaling
you can code almost anything you want and here is about Mesh of sprite
Related
I'm trying to rip the among us textures into Unity, but I'm having trouble with the spritesheet for crewmate animations like walking, venting, idle, etc.
Here's the spritesheet I'm talking about: https://github.com/Overload02/among-us-assets/blob/main/Players/Player-sharedassets0.assets-55.png
You can see it is not consistent at all, making a uniform square or rectangle cut impossible.
What I tried originally is just creating all the boxes manually, but this looks terrible.
How does one handle this elagently?
Maybe you could use each sprite as a seperate image instead of a spritesheet. then you could edit the edges of each one seperately.
I'm looking for ways to clip an entire unity scene to a set of 4 planes. This is for an AR game, where I want to be able to zoom into a terrain, yet still have it only take up a given amount of space on a table (i.e: not extend over the edges of the table).
Thus far I've got clipping working as I want for the terrain and a water effect:
The above shows a much larger terrain being clipped to the size of the table. The other scene objects aren't clipped, since they use unmodifed standard shaders.
Here's a pic showing the terrain clipping in the editor.
You can see the clipping planes around the visible part of the terrain, and that other objects (trees etc) are not clipped and appear off the edge of the table.
The way I've done it involves adding parameters to each shader to define the clipping planes. This means customizing every shader I want to clip, which was fine when I was considering just terrain.
While this works, I'm not sure it's a great approach for hundreds of scene objects. I would need to modify whatever shaders I'm using, and then I'd have to be setting additional shader parameters every update for every object.
Not being an expert in Unity, I'm wondering if there are other approaches that are not "per shader" based that I might investigate?
The end goal is to render a scene within the bounds of some plane.
One easy way would be to use Box Colliders as triggers on each side of your plane. You could then turn off Renderers on objects staying in the trigger with OnTriggerEnter/OnTriggerStay and turn them on with OnTriggerExit.
You can also use Bounds.Contains.
I'm making a 2D sandbox game like "Terraria" and "Starbound". This is my game
The light is filling the whole terrain but i don't want it. I want following:
You're probably using Directional Lighting, which illuminates the whole terrain equally in the direction you made it.
You could use Spot Lights or Point Lights, which will illuminate only the surface you want to.
Edit: although using this method, this could take way more resources due to the number of single lights placed throughout the map.
What's the recommended way of adding collision detection to an SKTileMapNode for a side scroller?
Say I have a simple tilemap with just one single tile to use as the ground, how can I detect when my player sprite lands on one of the filled ground tiles?
I'm not entirely sure this will work, but it seems you could add a node to each of a SKTileMapNode's tiles and, based on whatever texture component is on it, give it a physics body appropriately shaped and setup for matching that texture.
Here is someone attempting something like this:
https://forums.developer.apple.com/thread/50043
You don't ask for it, but for greater granularity (eg a tile that's partially covered and needs a sloping physics floor element), it seems this would be the place to start:
https://developer.apple.com/reference/spritekit/sktiledefinition
But I can't find exactly how to know what part of a texture is on any given tile of a tile-map. There must be a way to do this, but I'm just not quite seeing it.
Hi Friends
I Want to make a simple gaming Application in which the user hit the car and car breaks from that point means the image get little deformed when the user hit the car image. I know everything could be possible with using of lots of images and get change when user hit that car image but i don't want to use so many images.
is there any solution for this , how can i deform the image ..sorry for my English but , here i paste a link of the game that is on flash and this is what i exactly want..
http://www.playgecogames.com/file.php?f=657&a=popup
please respond soon
thanks
You don't say if this is in 2D or 3D, or what techniques you're going to use.
If you're implementing the game using OpenGL, it's fairly straightforward. The object can be made up of a regular mesh, with the image as a texture mapped to the mesh. When the user hits the object, you just deform the mesh.
A simple method would be to take a vector in the direction of the hit, displace the nearest vertex by an amount proportional to the force of the strike, and then fan out in to deform the rest of the mesh in decreasing amounts. By deforming the mesh, the image texture will be rendered with all the dents or deformations you like.
If you want to to this without OpenGL and just straight images, you could use image resampling to simulate the effect. You have your original pristine image which is 'filtered' to make up the resulting image. At first there are no deformations so you copy the original image verbatim. Each time the user hits the object, you can add a deformation using a filter or transform within a local region of interest. This function would resample the source image in a distorted manner, causing it to look like the object is damaged.
If you look up some good books on game development, you'll find a great range of approaches to object collisions, deformations and so on.
If you know a bit about image processing technics here is the documentation for accessing the pixels of the image :
Apple Reference
You also have libraries for this such as this one :
simple-iphone-image-processing
But for what you want to do this might not be the easiest way. What I would suggest is that you divide the car into several images depending on what areas can be impacted. Then you just change the image corresponding to the damaged zone each time the car is hit.
I think you should use the cocos2d effects http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide%3aeffects + multiple images. Because there are many parts which drops after the player kick the car. Like when user kick the side mirror you should change the car image with without side mirror car image.
The person that has made that flash game used around 4 images to display the car. If you want the game to be in 2d, the easiest way is to draw the car, cut it into about 4 pieces (: left side + right side (duplicate of the left side) hood and roof).
If you want to "really" deform the car you'll have to use a 3d engine like openGLES.
Id really suggest doing it in 2d :)
I suggest having a look at the cocos2d game engine. You can modify images with effects, which are applied using a virtual grid. Have a look at the effects page in their programming guide.