Sprites keep "Falling" off when I hit play

Hello Everyone!

I am working on a side scrolling shooter and have a few questions. I have only been working with Unity for a few days and I am amazed at the number of helpful tutorials both on this site and on the web in general.

I am having trouble in a few areas. I am learning C# as I go and borrowing libraries of code with heavy examination to comprehend it. I am using a tutorial to get my feet wet and I am following it to the letter.

I set my background, which is 2 layers set to position Z 2 and Z 4 that will allow parallax scrolling (once I get there)

After that, I import my player sprite, set it to position 0,0,0, scale is 3, 2.5, 1 (just to get it to the right size.) I then create a Box Collider 2D component for it, then a Rigidbody 2D component for it. I reduce the gravity to 0 and check the Fixed Angle box. After saving the scene and hitting play, the sprite just falls down as if it has gravity, until it gets to the area below my background graphic and stops. If I check the “Is Trigger” box it does not fall. (this is not detailed in the tutorial. I was just messing around with the options and it worked).

With that done, I then load a script onto the player object that allows me to move the sprite around with the arrow keys.

Then I add my first enemy at position 0,5,0 adding the same components and options (which also gets shoved off of the play area unless I check “Is Trigger”) and add a script that just makes the enemy move to the left and off the screen view. The tutorial indicates that if the two sprites (which are on the same Z level) intersect, they will block each other (which makes since, because I haven’t defined any OnCollision behavior) but they just pass through each other.

What am I doing wrong? I can paste the scripts I am using here if that will help.

  1. Why do the sprites keep flying off the play area when I hit play, unless I have the Is Trigger box checked? They seem to move rapidly towards whichever side of the play area they are closest to.

  2. Are the sprites supposed to hit each other and stop? Or are they supposed to pass through each other if no OnCollision behavior has been defined?

I also have some questions about animating sprites, but I want to get the bones of the game in place before I start tackling that.

It sounds a lot like the player and enemy are interacting with some other physics object you aren't aware of ("move rapidly to towards whichever edge is nearest"). Try to ensure no other objects in the scene have colliders and see if that takes care of the problem. Hopefully that's the source of your other error also.

–

Well, are you using BoxCollider2D and RigidBody2D ?? just with BoxCollider2D the 'Z' Value is ignored and what gravity did you change ? the gravity at the Engine, or the GravityScale at the RigidBody2D ? set GravityScale to 0 ...

–

The isTrigger box is for things that need to detect other rigid bodies, but don't actually effect there movement. Think pressure plates or infrared beams.

–

1 Answer

1

sorry for the almost 5 year late response, but have you tried going to edit > project settings > Physics2D > and turning the “y” setting to 0?