GameObjects Falling

Hello

I made some GameObjects. When I play the Game, they fall down in space. What do I do to prevent them from falling?

Perhaps don’t make people guess by only putting “I made some GameObjects.” :wink:

GameObjects don’t fall so I have to guess you’re using 2D physics? If so then you should’ve said you don’t want Gravity to be used on some (all?) of them. Set gravityScale to Zero on the Rigidbody2D in question. Of course, this is a guessing game right now. :wink:

Hi

Sorry for the simple Questions without adequate data. I am a newbie.

Yes you are right. I am using 2D physics. I did set the gravityScale to Zero. Now they are going up instead of falling down.

I have taken a snapshot of what I am doing. Hope that can assist you in your analysis.
(2DGame-Error.PNG - Google Drive)

Cheers
Deepak

If they’re going up then you’re doing something to them such as adding a force or modifying the position in script.

It sounds like gravity was causing them to move down countering what you were doing moving them up and now you’ve removed gravity, whatever it is you’re doing is moving them up.

This isn’t Unity doing this, it’s your code so I cannot really tell you anything else.

I mean, add a Rigidbody2D to your scene with a sprite and set gravity-scale to zero, it’ll stay there.

You don’t even say if it’s one platform or all of them! I suspect all of them.

I think what you’re telling me is all wrong. If I had to guess, because your camera is a child of the player, the “moving up and down” is actually the player along with the camera. The platforms are staying still which you’d easily be able to see because their Transform position (in your image) wouldn’t move. The platform you show has the BoxCollider2D disable so the player will fall through it.

I think you need to just step back and check your set-up. Try NOT having the camera follow the player like that so you can get your bearings.

There is no script for the Platform-GameComponent. The funny thing is the ‘Platform’ gamecomponent is now static (it stays there). However if I create a exact copy of it(Platform1) and place it in the scene, it moves up!

Did you read what I said about the camera and the player?

It just looks like the player is falling and the camera is following.

How do I fix it? Please see attached the script for the player attached.

P.S: Game video :

I cannot tell you “how to fix it”. If this is the tutorial you followed then why can you not go over the tutorial again and fix your mistakes?

Ok. I went through the tutorial many times, however without success. Anyways, thank you very much for your help.

I saw in your video that the player is rotating so I guess you didn’t see the option that stops that here:

“We also want to fix our orientation to prevent the character spinning and freewheeling around. Find ‘constraints’ in the inspector with the player selected and tick the box to freeze rotation Z. Now click play again and you should find your player now drops from the sky to his infinite doom.”

Also, it looks like the Platforms in your video are moving but in the tutorial, they are not so you should not add a Rigidbody2D to them otherwise they’ll move when the player touches them. In the tutorial only a BoxCollider2D is added to the platforms, to give the player something to collide with. They do not need to move so by NOT adding a Rigidbody2D they are implicitly Static colliders i.e. not moving.

The tutorial for set-up is easy:

  • Drag Platform Sprite into view, add a BoxCollider2D
  • Copy Platform as many times as you like
  • Drag Player Sprite into view, add both a Rigidbody2D and BoxCollider2D and set the Rigidbody2D Constraint Z rotation to stop it rotating
  • Drag the MainCamera to be a child of the Player GameObject
  • Add the scripts in the tutorial for movement/jumping.

Hope this helps.

I tried fresh again. It works. Thank You

1 Like

Good luck learning. It does get easier as time goes on. :slight_smile:

1 Like

Thank you so much :slight_smile: :slight_smile: :slight_smile: