Object drops when teleporting - unity3d

I have a cardboard box that can be picked up by the player. I have set up a mesh collider on this box and now it keeps any items that get picked up by the other hand within. However, as soon as I teleport, the items within the box do not follow the new position. Any idea how to achieve this?

When you teleport (I assume you just change the transform position), it goes in that frame to that position, colliders and physics are ignored.
A simple way would be to make the cardboard box a child of the player as soon as you pick it up (most VR frameworks already do this), and then items that go inside the box a child of the box.

Related

How can I remove small part of collider of game object in unity 2d

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)).

Player falls halfway throufh the floor till the outer edge of collider. instead of the inner edge

As you can see in the included video the player falls over the floortile till the outer edge of the floor. Instead it should stop at the inner edge of the tile so it looks like its standing ontop of the tile. Can anyone help? I cant find anything on the internet regarding my issue.
Im sorry if this is a easy fix. Im a beginner. This for a school project :)
Video: https://streamable.com/99jz2o
enter image description here
Photo of sprite standing on the wrong edge of the tile.
Edit: I went back to the tile palette and redrew the level. This time selecting the game object + bitmap again. Now it works. Probably the reason why it didn't work was that when I drew the level I had not added Tilemap Collider 2D and Composite Collider 2D. Now redrawing with those 2 components added it works as it should!
The problem is with your tile map collider. Instead of using this, set empty game objects as children of the objects that make up the . Then, add BoxCollider2Ds to each one, and add scale them to fit the map. If that doesn’t work, then it is either a problem with the rigidbody, or the box collider, make sure that all of the settings are set to default, then slowly change them back, and you will discover what is causing the problem. Then you can comment on this post what variable changed it.
Your issue is the Composite Collider. The docs specify that they
do not define an inherent shape. Instead, it merges the shapes of any
Box Collider 2D or Polygon Collider 2D that you set it up to use
When you attach a BoxCollider2D or PolygonCollider2D, there is a check box on them that specifies Used by Composite. When checking this box, other fields will disappear as they are now controlled by the CompositeCollider.
To use this collider, make a new object that will hold all your other colliders or make a few that hold sections of your map. Give this new parent object a CompositeCollider2D and give all the children BoxCollider2D or PolygonCollider2D. After this, make sure to check the box Used by Composite on the children Colliders.
Edit: Sorry just saw you were using a Tilemap. Just make the CompositeCollider a parent of your Tilemap while keeping the Used by Composite checked.
Edit 2: I am not too familiar with Tilemaps with Composite Colliders, but one other solution you can try before re-childing is changing the Geometry Type field on your CompositeCollider from Polygons to Outlines.

World space button click event to take priority over the collider's click event it's inside?

Short story:
I have a button on a world space canvas with a click event handler. This is inside (in 3d space not parenting) of a 3d collider with it's own click event.
The collider always gets the click event as expected as it's nearer the camera.
I want the button to get the event.
Long Story:
I have a person mesh with a collider. You can click on them and the OnPointerClick triggers to do something.
I have a button that sits in a world space canvas which itself is located just above the mesh and is pointed towards the orthographic camera. You click on the coin and the OnClick event triggers to do something else.
Both events work as expected until the coin is inside the mesh's collider (which it is a lot of the time). At which point it's ONLY the mesh collider's OnPointerClick event triggers, not the button.
However, I ALWAYS want the button to take priority over the collider, and any other collider. This is easier when the canvas is screen space, but it's not (with reason).
How do I do this?
NOTES:
The button never gets the onclick event, so any filtering on the containing collider won't help
I've fiddled with the world space canvas and camera ray filtering settings to no effect.
The coin has to be a world space canvas for automatic tracking and because I use text too
IsPointerOverGameObject doesn't help as it's true for any collider, not just UI elements. Not to mention it wont stop the collider consuming the click anyway. A custom version of this that works via a layer wont help either, because again the OnPointerClick on the collider GO stil consumes the click.
I don't want either event to have to do any event filtering & passing on if possible, they should be atomic. Any filtering should be via setting properties in objects and inherent functionality of Unity if possible
Just to reiterate, writing a function to find all objects in the ray and then selecting ones that are on the UI layer first wont help. Because that does not change the fact that the collider still is the only thing that gets the event, which then you'd have to manually propagate down to the button.. which I don't want to do.
I've been able to fix this by putting the button's world space canvas on a sorting layer of 1. That way, even if it's behind colliders, it will register first.
Nice and clear solution that I was hoping would exist.

attempting to pick up Object in unity is invisible but collider box can be seen

For some reason, in my game, i am able to pick up every object i want except my Oar prefab.
It shows in the editor scene that the object is picked up but is invisible, all i can see is the collider box and outlines
When i pick up the sword, it appears in my hand. As you can see, the Oar image is on the ground however, the collider box is in the player hands.
I am trying to make it look like my sword.
If im not mistaken, there is a box collider on both the GameObject(parent) and the model(child). You could try removing the collider for the parent or the child, as having a collider for both might result in some weird behaviour.

How to move a tile (sprite) with drag and drop in Unity 2D?

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