I have a very tall, and thin, tower of cubes one on top of the other, each with a rigidbody attached.
I'm trying to build it higher and higher and have a wind blowing at random heights to try to blow it up and demolish it. It seems simple, but I can't do it properly.
I need to do something as the wind zones for tree, and I cannot attach the forces to the cubes since I need something to instantiate randomly at certain times or places that "pushes" the cubes to make them fall.
I've tried with a particle system, but I was unable to make the particles as collider objects (is this even possible?).
Any suggestion?
Interactive cloth might be your choice.
To add an Interactive Cloth in the scene, click menu
GameObject -> Create Other -> Cloth.
Add new anchor GameObjects (Menu GameObject > Create Empty Object)
For each game object, add a collider component (Menu Component >
Physics > Box Collider)
For each collider, specify the center and size of the collider
For each collider, specify the 3D location of collider, at which the
cloth remains static
Make sure the collider overlaps/intersects with the cloth, otherwise, it won’t work.
For your case, if you wish to programmatically specify the anchor position (since it is random), you might wish to refer to this tutorial as well.
Related
click here for gif show of what I want
I want to remove mesh of object when user click on object and also remove its collider to make another object fall from that removed mesh area...
I am using unity since last month so I don't have much experience and knowledge, please help me...
Creating the destructable ground particles
One way to achieve whats shown in the gif is by creating a prefab of e.g. a circle collider that is instantiated in the area of where the dirt is in your gif. It acts as a "ground particle" and keeps the objects above itself.
You instantiate a lot of them in the area so it acts as a big collider although it is actually a whole array of smaller colliders.
Implementing the interaction logic and deactivating the ground particles
Ater that you implement the functionality of dragging the mouse over the ground particles, removing them. That is also not difficult. Shoot raycasts into the screen at the postition of the mouse (remember to use Camera.ScreenToWorldPoint) and get the collision information (confer to https://docs.unity3d.com/ScriptReference/Collider2D.Raycast.html). With the collision information you can get the reference to the instance of your ground particle(raycasthit.other.gameobject) which is then disabled through script(gameobject.setActive(false)).
I have a gameobject player that has a character controller and a gameobject cube that has a rigidbody.
I'd like to make my character go through the cubes like a Trigger. Except that I want the cubes to keep their gravity and physics.
I did a little research and found Physics.IgnoreCollision or the layer collision matrix. Both methods work, I get through my cubes well, except that I have a weird behavior that makes me feel like I'm bumping into each one of them, so I find myself slowed down in my momentum...
Is there a solution to my problem?
In the Unity menu bar, go to Edit > Project Settings, then select the Physics category to open the Physics window. You will find a Matrix and here you can uncheck the collision between 2 layers. If you put the cubes in a layer and the player in another layer and in the matrix you uncheck the box, cubes will maintain their properties and player will pass through them.
i've made a simple pot model inside blender:
So the idea is that after importing to unity, generating mesh collider, adding ridgin body i would like to be able to put smothing inside the pot. Now it's generating collider but without a "hole" inside, so if i throw smth inside it just bounce off the top. Is there any way to do it simple way? I'd like to avoid making a collider by hand in unity, using cubes and so...
Image overview:
Your collider needs to be concave
It isn't clear from your question how you're "generating mesh collider," but the results are clearly generating a convex collider.
That said, some things to know about mesh colliders (and concave ones even more so): They are very compultationally heavy to calculate, so they should never...
move
scale (especially non-uniformly)
rotate
...at runtime.
Alternatively you can use multiple box colliders in the same orientations as the side-segments of your can (along with one or two for the bottom, depending on how small of an object you'll be dropping inside).
Uncheck the generate collider box from the import settings, add a mesh collider component and check convex.
I would use four or six box colliders for the walls of the pot and another for the floor. You can scale each box collider along each axis, but if you want to rotate a box collider you will need to give it a parent and rotate the parent. Box colliders are very low cost for the physics engine compared to mesh colliders.
The character can enter the elevator but the problem is that he can also walk through the walls from sides and behind.
And if i add a box collider or any other collider/s they will prevent from the character to enter the elevator. It's not my elevator object it was made in blender.
Use Compound Collider instead of Mesh Collider.
Create new empty GameObjects called back, front, right, left, top and bottom
then attach Box Collider to each one. Manually resize and move each one to match the size of the elevator on all sides.
Once that is done, put them in a parent empty GameObject then put that parent GameObject under your elevator GameObject so that the colliders will move/rotate with the elevator. Finally, disable or move the front Collider GameObject via code when you want to allow the player to enter inside the elevator.
The image below shows example of what individual collider should look like and the final look:
These sorts of questions are better off in the Unity Answers, as this isn't a programming question. Please keep that in mind for future questions.
To answer your question though,
Find the mesh in your Project Files in Unity, there is a checkbox for 'Generate Colliders' - check this box and press apply.
Finally, on the GameObject with the mesh, add a MeshCollider component.
If the model is set up correctly, your mesh collider should now use the model for collision.
If this does not work, as an alternative, you can use cubes with colliders and 'build' the collision mesh yourself, and parent the objects to the same object so they move with the lift, before disabling the MeshRenderer component so they will not render.
I would like to move a tile with drag and drop in Unity 2D. The tile is a sprite. The scene is an 'Unblock me' or 'Blocked in' like gameplay.
Because the tiles in real life correspond to physical objects it seemed be to a good idea to model them with colliders and rigidbody. The border of the table surrunded with invisible colliders. I hoped these will constrain the moves of the tiles realistic, when the player moves them.
Then I implemented a simple (mouse based) drag and drop behavior which is worked perfectly except the moved tile penetrates to other tiles and the border, and sometimes jumps over them. Then I learned if I am overriding physics by explicitly setting transforms position (which I do exactly in my drag and drop implementation), this will happen. OK I accept, I should set only forces, ect. on rigidbody never directly the position.
Now the question:
I am stuck here. I still want to drag and drop like user experience, and some realistic visual result. When in the real life a player moves a tile, it seems it is "glued" to its finger. How can I achieve this (ot at least similar) with just applying forces? Any suggestions or point similar existing sample/blog code?
(I know as a backup plan I can omit all the physics and constrain the tile positions by code, and create some tweens to move the tiles. Is the real solution (what I am asking for) so complicated I should vote on this backup plan?)
Edit
According to comments I've added a video:
There is nothing wrong with the way you are manipulating your dragging. The beauty of developing is being able to do things in your own way. If it works for your game, then don't fret.
Now, i recommend:
Create a new physic material. Assets > Create > Physic Material
Set your new physic material inspector settings both to 0
Attach the physic material to all your wall object colliders. This should allow for your object being dragged to move smoothly against the walls without chopping.
Do a check to see if your mouse is over another collider. If so, then stop the movement in that direction.
Since your movements seem to always be on a single axis, on collision, tell your object to snap to the edge of the wall object. You know the Wall position and scales, also you have the position and scales of the object being dragged. with that you can write a function that will offset it to the correct position when the collision occurs.
Let me know if any of that works out :P