Why is my character flying off in unity 2d? - unity3d

When i Click on the play button my Spire flies off into the ceiling of my map.
I have a simple png as a sprite in unity.
I use a tilemap for the level i made which has a TilemapCollider2D and a BoxCollider2D.
https://imgur.com/2tggchP <- photo of what is happening.
My character has a BoxCollider2D and a Rigidbody2D.
I'm making a side scroller in case that is necessary to know.
The gravity and stuff for the character is normal and so is the mass.
My character(s) should just stay on the ground.

I'm not exactly sure if the grey part of the backroud is the object that has a BoxCollider2D but if it does that that's your issue.
You can't have two BoxColliders overlapping each other otherwise you'll get what your seeing now, one shooting up.
I would suggest removing the BoxCollider2D on the tilemap (if that's possible) and maybe just having a BoxCollider2D on that floor in the picture.
If my answer didn't help or wasn't good enough I would be happy to help you further, just reply to this. :)

Related

How to fix the ground in unity 2d

Um I'm making a game in unity I got a problem I made a picture as the ground but it doesn't work I put if to default and put what is ground to default to I use rigid body as physics and I already put a collision box and collision circle
Your question is not a clear question
But be sure to add the rigidbody to the ground and the box colliser for the player and the ground
You can review the images in this question showing how you can add the rigidbody and the box collider
Adding on to the responder above me, even if you did add the colliders, you may not have made the right size.

Objects not colliding Unity2D

I am trying to make a Retro Tenis Game in Unity2D but I have some issues with the colliding system.
My controller does not collide with the walls. It goes through them.
It should stop in the wall like pic1 but it goes through it like pic2.
Can anyone help me, please?
pic1
pic2
UPDATE#1: I added a RigidBody component but it does not fix it. (pic3)
pic3
You shouldn't use the colliding system for this purpose. It would be much better that the script in charge of moving your paddle was able to control its maximum and minimum height too (note that the screen size can change, and the paddles should move at different heights depending on the screen size).
Although if you want to do it with the collision system and "walls" that limit the space of the paddles, both the "walls" and the paddles need to have a correctly positioned BoxCollider2D and the paddles an extra kinematic Rigidbody2D too (as they can move).
Also make sure to move the paddles using physics and not modifying its position with transform.position (see Rigidbody2D.MovePosition)
Edit: Unity2D physics system is rather a complicated topic and difficult to get it well on your own. I'd suggest to learn the basics in the Unity Learning Platform. You could start with this project.
You need add RigidBody2D to your "circle"

Setting up a sliding character in the right way

I would like to try and make a game similar to Altos Adventure. I am having trouble starting.
How to set up the terrain so that my character doesnt get stuck?
I simply drew a test sprite for the ground in photoshop. What collider2d should I use?
I use polygon collider and reduce friction in the material. But the character gets stuck, hits small invisible bumbs and it feels awful. The worst part is connecting 2 ground sprites together! The point where they connect is always messy.
I have a question for the future as well. How would I add the endless part of the game?
Would having many "pieces" set up and just spawning them as the player rides down work?
I havent written any code yet as the problem is simply in the physics in my opinion.
Thanks to anyone who takes the time and tries to help!
To move your player use rigid body.AddForce(Vector3 direction, ForceMode forceMode); then create a Physics Material with friction = 0 and put it in your player's collider.

swift usesPreciseCollisionDetection does not work?

i have made an app where you need to shoot on an enemy but sometimes the bullet goes through the enemy. swift sprite kit game when I shoot on a enemy sometimes the bullet goes trough the enemy, how can I fix this?
so i added usesPreciseCollisionDetection = true.
but the bullet sometimes still goes trough the enemy. so my question was did i do something wrong or is usesPreciseCollisionDetection not working?
thank you for reading my question I hope someone can help me.
You are using moveTo to move your bullets, Physics Engine does not work with moveTo the way you want it to, usesPreciseCollisionDetection will not do anything
As far as your Physics World is concerned, your bullet is stationary. You are just playing God and performing some kind of molecular transportation to move items.
You need to use functions like applyImpulse or even just give the physicsBody a velocity if you want this to work correctly
I had similar problem that is collision was sometimes not detected even when usesPreciseCollisionDetection was set to true and both SKPhysicsBody were rectangles. In my case usesPreciseCollisionDetection for some reason started working much better when I changed one of the SKPhysicsBody to circle instead of rectangle. Try changing your bullet physics body to circle, it seems that collision detection algorithm with circles is more precise so that might help you.

Side scroller style scene with gravity

I've started learning sprite kit and I think I've got the basics but now I'm struggling with something.
I want to create a game that has a 'Streets of rage' type feel to it whereby the user can move up and down, but isn't jumping, they're still on a 2D plane. But I also want them to be effected by gravity e.g stairs etc. like the following picture.
Am I right in assuming that I should have my background image with colliders around the blue and brown edges, and then create a physicsbody collider located at the feet of my player/players so that it looks like they can move against the background, but when their feet reach the top it would stop?
Could I then place other obstacles like rocks etc on that path that they would be able to collide into, but that could also sit over the path and the sky? How would I handle the fact that these could be constantly colliding depending on the position?
I appreciate there isn't any code here, but I'm trying to understand the concept around this before I jump in coding a solution.
Thanks
I would use a categoryBitMask to separate the different planes of objects.
And I would play with collisionBitMask/contactTestBitMask depending from the plane the player is in, in addition to the z-order.
Thus you can have a rock that collides your player if they are both in the same line else the player would walk behind/front.