I am currently working on a 3D Unity game in which you control a block through a labyrinth made out of blocks and have to avoid spikes, moving enemys and other traps.
Here a picture how it looks at the moment ( you are the blue cube and have to avoid the moving pink ones ):
The problem now is, that when I move along a wall, the player gets stuck and stops moving until I move in the other direction again (every part of the wall is as big as the player because I am generating it from an image).
I already tried everything with Physics materials and friction but it does not get better :(.
The problem is that your BoxCollider of the player is probably getting stuck on the edges between two of the wall colliders. Consider "smoothing" the edges of the collider a bit so the player wont get stuck.
The default collision detection mode in Colliders is Descrete, it might jump through a small gap occasionally, you could set the players collider to CollisionDetectionMode.Continuous it will prevent the overshoot.
Try decreasing the Default Contact Offset in Edit/Project Settings/Physics
Changing it from 0.01 to 0.0001 worked for me
Source
Related
I'm having an issue where I can't walk up slopes in unity. My art is pixel so I understand the slope is made with a gap of 1 pixel to create the actual slope, but I have no idea how to fix it so I can just walk up and down them normally. Currently, going down them makes it a little bouncy and going up them is impossible unless you jump. Any help would be appreciated! Here is what the slope looks like:
Edit: Collider looks like this but I don't know how to fix it:
Sprites automatically have a polygon collider created for them when imported into the project. This polygon collider drives the tilemap polygon collider shapes.
You can modify the physics shape for a sprite to smooth it out and remove this unwanted when going up a ramp. Custom Physics Shape documentation
Another important thing to note in your specific problem: Often when a character has a "box-like" shape, they will get snagged on edges and small collider deviations. Unless your game's playstyle is based around a box-shaped entity and interactions, it's usually recommended to use a rounded collider for the moving characters (like a 2d or 3d capsule collider).
im working for 3rd person fighting game between two characters.
I've setup camera to focus enemy and player in same time like Naruto Ultimate Ninja Storm 4, but when camera collide with wall the view angle will be change and both characters will not appear on screen.
in Naruto Ultimate Ninja Storm 4 there is transparent wall around arena which leave empty space between visible object (wall,rock..) and player but allows camera to pass it.
my problem I don't find method to let the camera pass this transparent wall and stop player to pass it.
I tried to get tag of object in collision and disable collider of object when is camera or vice versa but that allow character also to go tought transparent wall
You should create 3 layers, if you haven't already:
Player
Camera
Wall
Put each GameObject in the corresponding layer, then go to Edit->Project Settings->Physics, scroll to the "Layer Collision Matrix" and uncheck the collisions you don't want to have. In your case, you want the collision between the wall and the player, but you have to uncheck the collision between the camera and the wall.
Also, to make this work correctly, make it so that none of the characters, walls, and camera are separate gameobjects.
This is also very useful to remove any unnecessary collision and boost your game performance.
So I'm making a 3D pool game. Basically I have a main camera that when you press a button it adds force to the cue ball based on the position of the camera, which works ok.
But whenever the cue ball hits the wall of the table, it just stops. I want it to smoothly bounce off the wall like a real pool cue ball would.
The cue ball is just a basic sphere Game Object. The walls are basic cubes with colliders.
I have tried Vector3.Reflect with no success. It seems to bounce back a tiny bit but then immediately stops.
Any help would be great!
You should create a PhysicMaterial with low or no friction (both dynamic and static), bounciness = 1 and Bounce Combine = Maximum and then apply that PhysicMaterial to the rigidbody of your sphere
You can do one thing.
Store the ball velocity when it collide with the wall, calculate the reflected direction through Vector3.Reflect and give the stored velocity to the ball in reflected direction.
Hope that this will help you...
Best,
Hardik.
To make bounce on wall we need to create physic material and after that we need to change the value of dynamic friction =0.3 and static friction =
0.3 and bounciness=0.8 and frictionCombine choose Average from dropdown and bouncecombine choose Average .
Hence the ball is start bouncing on the wall by using the upper property.
I have used polygon collider for the hills and terrain like sprite in my 2d game.
I used the same polygon collider for my hero character. Here is my problem the movement is smooth when i used box collider in hills and all that but it makes my character look like floating in air. so i opt to use polygon collider for hills.
However polygon collider produces some small pit or irregular shape to fix the best possible shape of collider for hill. Here my player or hero get stuck in those pits or irregular shape. Even the slightest pit cause my player to strand. I tried various way to mitigate all those errors but no any result.
Please suggest to me some way to make my character movement smooth in uphill.
Instead of using one collider, try 2 different ones for your player. Put a box collider around his mid section and head, and a circle/capsule collider that goes around his feet. That way you get the circle/capsule collider will reduce the chance of your player getting stuck on awkward locations :-)
You can always try to edit the collider yourself, or even start with an EdgeCollider and make the shape yourself. Anyway, I don't know how irregular those "pits" are, but you can always edit in a very easy way the collider in 2D.
Oh, and you can edit the collider in the component itself, and then in the editor window.
I've got a coin RigidBody and walls around it with box colliders. For trial purpose I've applied the following code to the coin.
private void OnMouseDown()
{
rigidbody.AddForce(30.0f, 0f, 5.0f, ForceMode.Impulse);
}
But, sometimes the coin passes through the walls, but when I increase the speed from 30 to 50 points it passes through the walls on the first click. I've googled a lot and still got nothing except for the DontGoThroughThings Script which doesn't work for me or I don't really know how to use it.
I've always added a continuous dynamic on the coin and continuous collision detection on the walls but still doesn't work.
the problem with physics collision detection is that sometimes when the speed of an object is too high (in this case as a result of a force added to the rigid body) the collision wont be detected. The reason is that the code you are executing is running at x ammount of steps per seconds so sometimes the rigidbody will go through the collider between one step to another. Lets say you have a ball at 100 miles per hour and a wall that is 1 feet wide, the code will move the ball a determined ammount of feets everytime the code is runned according the physics of it, so the movement of the ball is virtualized but its not a real physical movement so it can happen that from one step to another the ball can move from point a to b and the wall is between those points and as a result the collision will not be detected.
Possible Solutions.
You have a simple solution that wont be as accurate as it should be and a harder one that will be perfectly accurate.
The solution number one will be increasing the colliders size, according to the max speed your coin can get, that way the collider will be big enough so that the collision wont be missed between one frame to another.
The second and harder solution will be adding an auxiliar to your collision detection, some kind of a security check. For example using physical raycast. You can set a raycast to forward direction and determine if that object is an inminent collision, if it does and once the object isnt being collided by the raycast anymore then your collision detection had failed that way you have your auxiliar to confirm that and call the collision state.
I hope it helped and sorry about my english. If you didnt understound it very much i could help you with code but i will need some code from your project.
See if the colliders have their 'Is Trigger' unchecked.
Also, check if the gameObjects have colliders.
I have faced this problem many times..
Make sure Your coin's Rigidbody has "Is Kinamatic" False, Is Triggger:false,
And also "Is Trigger" of walls is False.
You could save the velocity and position on each update and then test for out of bounds, if the coin leaves the valid area you can restore it at the last valid position or plot the collision yourself if you want to