Unreal Engine 4 - Collider component sweep issue - unreal-engine4

I have a 2D environment where an object falls (a trap) and a box collider component is moved with a timeline to follow the movement with SetRelativeLocation.
Since the trap is near a wall if I leave the Sweep option unchecked in some cases the character will stuck mid air between the trap and the wall.
Sweep off
If I turn on Sweep this will not happen and the character is pushed to ground correctly but since the collider "slows down" for some frames it seems to be in the middle of the sprite.
Sweep on
Teleport option seems to have no effect on this behaviour.
Is there any way to have the sweep effect with the collider keeping his velocity and keeping the structure as it is with the collider moved by a timeline?
I feel like I'm missing something really simple but I'm losing my head on this.
Thanks!

Since it's 2D, have you tried blocking the input when your character collides? I would add a simple collider in front of your character and when it is overlapped, I'd limit the input in the direction your character goes, ie.:
Character collides right
MoveRight(float Scale): Clamp Scale to (-1.f, 0.f); AddMovementInput(...
Hope it helps!

Related

Unity: 2D character floating using BoxCollider2D

I'm pretty new to unity and I set up a simple scene with my character and the ground. I added a Rigidbody2D and a BoxCollider2D to the character and another BoxCollider2D to the ground. The boundaries of the Colliders fit the boundaries of the character / ground exactly, but my character is not falling on to the ground, when I hit play, but rather stops and floats a few pixels above it.
I've seen a lot of similar questions but the solutions didn't work for me (or maybe I didn't understand them right, as I mentioned above I'm new to Unity and thats my first game).
That's what the floating looks like:
I could obviously "fix" this by lowering the upper boundary below the actual boundary of the ground, like this:
But that's obviously not a good solution and I'd still like to know what is causing this bug and how to fix it.
Maybe gap has size of Default Contact Offset:
Set a proximity distance value for colliders to be considered in contact, even they are not actually in contact. Colliders whose distance is less than the sum of their contactOffset values generate contacts. This allows the collision detection system to predictively enforce the contact constraint even when the objects are slightly separated.
Caution: Reducing this value too far could cripple Unity’s ability to calculate continuous polygon collisions. Conversely, increasing the value too much could create artifacts for vertex collision.
You can find it in Edit > Project Settings > Physics2d .

Unity 3D object with Rigidbody sliding

I have a cube with Rigidbody attached to it would slide slightly whenever I pressed the play button. If I leave it for awhile, it would slide to other side of the screen.
Anyone know how to solve this problem without using the "freeze position"? I don't know what I messed up in my project...
This is what the object looks like:
Note: I need to use the gravity.
Thank you!
Heh! The solution here is:
You had a rigidbody on the floor :)
You don't do that :) Never.
If the "floor" surface is flat, then,
it will not slide.
You've got something strange going on, such as
"floor" is NOT flat
a feature like "Wind" turned on
perhaps other objects invisible in the scene you have forgotten about are nudging it
PhysX does not have a "mind of it's own". There is some simple reason it is moving.
Let's say the "floor" is indeed on an angle, so it SHOULD move, but you WANT it to NOT move.
What you obviously do:
Just as in the real world, put something there to stop it moving.
A small invisible wall will do the trick. That's PhysX!
Usually rigidbody sliding happens when a lower rigidbody has lower mass than a higher rigidbody (forcing down the lower rigidbody). Typical problem with player having say mass 80 jumping on a cube with mass 1. In this case the collision is so violent that the cube will probably fly out (not only slide).
The situation is very similar to the real world. Try to stay on a box of milk if you have 120 kg (ok, ok, 80 :) ).
When you try to eliminate this behavior, you need either increase the mass of the lower object or decrease the mass of the higher one or set the lower rigidbody to kinematic.
The solutions above is not proper way of solving the problem. Unity has more features of physics than mass. If you get sliding on movement or because of other objects you should add proper drag value on your rigidbody. For example , lets say you have blocks spawning over top of other blocks and this creates horizontal sliding. In my case I add drag of 1 to the objects which has mass of ~ 1 kg. It depends on the scene and you should try different values on your case. Do not use bigger values and angular drag if it is not important.

Unity Friction Issue

I'm having a simple cube which is my character that can jump on a moving quad (left to right vise-versa) having a collider with friction physics material.The issue i'm facing is when the character jumps on the moving quad, instead of carrying the character along with the quad it leaves the character, friction didn't happen between quad and character in order to carry the character.I tried playing around with physics settings and also tried with a cube instead of a quad.
Im tweeting the quad for animation(Dotween),character has collider (friction material),rigid-body (angular drag - 0.05,drag - 0)
Screenshot of my character and quads
My Issue of quad moving without character
I don't understand this should be taken care of unity's physics engine.we shouldn't be configuring unnecessarily or am i missing something?

2d collisions not working properly

Working on a platformer game.
For example, collision without logic will overlap each other when you give velocity to one of them (I solve it with triggers that prevent movement to side where other collider is near).
Now I face an unsolvable trouble. Sometimes my character gets stuck in walls
or cant fall because unseen collision happens.
1 - box collider
4 - box collider
2,3 - triggers
Searching haven't give me structured and right answer, so please, help me solve it.
P.S. Character controller script - https://github.com/rincew1nd/Sleepy-mole/blob/master/Assets/Scripts/character_controller.cs
P.S.S. When I turn off "fixed angle" on character rigidbody2d, all works fine, but physics change a lot and I wanna rigidbody2d with "fixed angle".
I have find an temporary solution for this issue, but it like "invent a wheel", so i still need better solution. Turn on/off fixed angle of rigidbody2d if position not changed for a while and character is not grounded.
http://pastebin.com/Qsm4HACj

Unity 4 Character Mesh Collider not aligned - character falls through. Image attached inc source unity asset link

Hello Peeps (first post yay).
I have just started to learn about unity and still going through various tutorials and learning the interface along with C#.
I am running Unity 4 and downloaded a free asset from the Unity store:
https://www.assetstore.unity3d.com/#/content/3174
The Problem.
I created a Plane in Unity.
Went to the Character and created colliders and imported it as a humanoid.
Then added a rigid body = The character fell through the plane
I then added a Mesh collider and attached the mesh for the character to the collider. The mesh does NOT align correctly to the character = the character fell through the plane.
I then tried box and capsule colliders and they worked fine. Attached these and the character would not fall through.
I then tried a character controller = Character did not fall through.
I want to have an accurate mesh for this test character so when an enemy hits him, there is an actual hit.
I have tried several other free characters from the store and they all have the same problem. Can someone please tell me how I can fix this? It seems I just either doing something completely wrong, missing a step or just plain lost.
Link below to image of the issue taken:
Using a mesh collider on a skinned, animated character is a wrong approach. Mesh colliders are generally used for environment geometry and rigid objects. This is all due to the amount of work it is needed for the Unity engine to accurately calculate the shape of the mesh collider, based on the provided mesh. More triangles means more work, and for the reasonably complex low poly character mesh of 10k to 30k triangles it is clear that the fps would most definitely drop to an unplayable level.
For our game we are using all primitive colliders, distributed on the adequate bone game objects. So, head bone has a sphere collider, spine has a box collider (for lungs), forearm has a capsule collider etc. That way,with a little bit of scripting, you can detect a hit and know exactly what part of body is damaged.
If your collider doesn't exactly match your mesh, then it's likely that you have the mesh applied to the wrong part of the object.
Try applying the Mesh Collider to the mesh, instead of the complete object.
You have a pretty complex character mesh, so using mesh collider probably isn't the best way to go. In many cases, character controller or capsule collider works fine; otherwise, you can just use compound collider and create a box or a sphere around various body parts of the character.
This once happened to me. The mistake i made was, i applied the mesh collider after i did some rotation and scaling. So i added the mesh collider as soon as i imported the model. And then it should be alright when you scale/edit the model. Also check with right/left handed co-ordinate system with unity and 3D MAX/Maya.