Unity: fixed Y axis of prefabs - unity3d

I am building a top down shooter using the unity survival shooter assets. The problem I face is that all of the spawnable prefabs(enemy, player) have a fixed Y axis position. This is sometimes causing them to float in places where the ground level is low and sometimes they will sink where the ground level is higher. They do not change or update the Y axis as the terrain does.
How can I fix this so that the prefabs move according to the terrain.
Enemy Settings
PlayerSettings
Scene Screenshot
Terrain Navmesh

I would recomand you read this: http://answers.unity3d.com/questions/197952/rigid-body-and-character-controller.html if this doesn't solve your problem,
first I would try to play around with the mass and angular drag. Second of all I would rebake the nav Mesh. Third I would change the slope limit and step height and rebake again. And last I would try to use agent.updateposition = true; and agent.updateRotation = true;
I hope at least one worked. Happy coding !

Related

Unity player boxcollider 2d Contacts Normal Vector bug

This bug occurs very rarely (probably 1 in 100 collisions with a platform) where the players box collider 2d have contacts with the platform horizontally (two contacts with (-1,0) vectors and two (intented) with(0,1)). This is very problematic because the player cannot jump forward (just jumps up without any x velocity) and it looks like it hits an invisible wall. I tried increasing the default contact offset in the physics 2D settings to 0.01 but it did not help. I am creating a pixel art game with 16 Pixels per unit.
After researching I finally found a fix for my problem. My problem was that the player got stuck inbetween my tiles each having a boxcollider with the TilemapCollider2D. I fixed it by removing each collider to one whole with a composite:
add TilemapCollider2D to the tile layer's component
check "used by composite" field in TilemapCollider2D
set Rigidbody2D to static
I had to check composite collider to polygons because otherwise I could not apply any Force to the rigidbody somehow.

[Solved - 3D movement on X and Y with mesh colliders

I am working on an Asteroids clone in 3D with top-down camera. This setup is static and will not change (so no, I do not want to transform the project to 2D game instead).
This means that I need to limit all movement to X and Y axis. I created movement for both asteroids and player and everything worked fine. All movements are done using AddForce on respective RigidBody components.
The problem is then I start dealing with collisions. I use Mesh Collider components to get a nice and precise "touch reaction". The problem is that when collision like this occurs, the new movement vector has Z value different from 0. This is a problem as the object will start moving on Z axis.
What have I tried:
Freezing constraints on RigidBody
Manully reseting Z in Update function
The first solution (freezing constraints) did not work and neither did the second one (moreover, the second one seems quite messy)
So the question is
What would be the optimal way to force physics-based movement only to X and Y axis while using precise collision with Mesh Colliders?
are you sure you used the position restriction correctly? You can check to set the restrictions with a vector as in the documentation. https://docs.unity3d.com/ScriptReference/RigidbodyConstraints.FreezePosition.html
to see how its done. If not please share the code or a screenshot of the rigidbody restrictions you tried in the editor

Unexpected trajectory after a collision

I'm currently trying to develop an arkanoid-like game in Unity but I'm having a problem that I can't seem to be able to solve with a satisfying solution.
When the ball hits the edges of two adjacent bricks, it "reflects" the velocity in an unexpected way: the ball goes to the direction where it was coming from.
For information, I have a world space size of : 5.625x, and each brick has a size of 0.703125 for 8 bricks per line. Also, every bricks have the same Y size for the collider.
I tried increasing the x size of the collider to some reasonable extent (0.74x for example) to make sure there's no gap between two bricks but the problem still occurs sometimes.
Here is a very ugly picture illustrating what's happening (the green arrow being the expected trajectory):
Thanks in advance for your help!
EDIT: Here are the inspector informations regarding the ball and the bricks. Regarding the lines of bricks, it's basically eight game objects with a boxcollider2d and a kinematic rigidbody2d.
The ball material has a friction of 0 and a bounciness of 1.

Unity 5.2 - Moving character bumps between 2D edge colliders

I'm creating a fast-paced, 2D side-scrolling game on Unity 5.2, building my terrain out of discrete "blocks", each with its own EdgeCollider2D component.
Having a problem where my character gets bumped upward as it crosses from one block to another (imagine driving your car over a speed bump on the road).
This doesn't happen all the time. Seems to be random, which is even more irritating, as it makes finding a solution more difficult.
I've tried all of the suggestions that I could find for similar questions on this site, including:
Using CircleCollider2D's on the character
making sure the terrain blocks and their corresponding colliders are perfectly aligned. The attached screenshot shows one of the intersections.
changing the "Min penetration for penalty" setting to the minimum allowed value (0.0001)
switching between discrete and continuous collision detection for the character's RigidBody2D
increasing the mass and gravity scale for the character's RigidBody2D
... to no avail.
Beyond building a single, massive terrain object with a single edge collider from start to finish (which I'm trying to avoid), I've run out of ideas. Anything else I'm missing? Is it just a Unity bug?
Help!
Try detect the collision and set the vertical velocity to zero.
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.name.StartsWith("block"))
rigidbody2d.velocity = new Vector2(rigidbody2d.velocity.x, 0);
}

How to change gravity direction on Sprite Kit?

I am using Sprite Kit in Xcode and I was wondering how to change gravity direction.As default gravity direction to "X" you can imagine on below axes graphic.What about if I would like to change to "Y".
My goal is giving to object the falling effect.Its like falling from hight point and touching the ground than getting respond with physics!
(Could be dices on board game)
//Default gravity direction is X
SKSpriteNode *myNode =[SKSpriteNode spriteNodeWithImageNamed:#"ball"];
myNode.physicsBody=[SKPhysicsBody bodyWithCircleOfRadius:self.frame.size.width/2];
[self addChild: myNode];
Thanks in advance!
You can apply a vector to the Physics World of your scene using this code
self.physicsWorld.gravity=CGVectorMake(0,-10);
In SpriteKit, X and Y are the default coordinates that you see on the screen, and the Z coordinate is the order in which the objects are positioned (the zPosition). Since SpriteKit uses a 2D game engine, you do not have a third dimension, Z, to utilize. You can change the gravity between Y and X (Top/Bottom and Left/Right of screen respectively), but not between the Z coordinate. If you want to recreate a "dice falling" effect, I would recommend you create a Sprite called Dice scaled to a large amount, and once you add it to the scene you scale it down in x amounts of seconds.
[self runAction:[SKAction scaleBy:negativeFloatHere duration:3]];
This will make the dice appear to be falling, and you might want to add some spinning animations for it if you with. If you want to use the 3D engine, go try out Metal or SceneKit