- Home /
2D game building
I want to make my 2D game side view so that in a mansion, there are rooms above (climb with ladders), below (more ladders) and to either side of the rooms with an end to the mansion after approximately 7 rooms in each direction. However, I have no clue how to make the gravity and platforms work. I'm probably overthinking it. Need quite a bit of help!
UPDATE Still stuck. thinking something to do with it being just a platformer with a different background. No clue how to do that either. Still clueless about the gravity.
Answer by DudeBrainz · Oct 13, 2016 at 06:59 AM
well i'm not good with unity, but i believe you could use a rigidbody and freeze it's x and y when you "climb" your ladder, and just manually manipulate the position. there are plenty of tutorials on the rest of a 2d controller. if by platforms you meant moving platforms, then just
OnCollisionEnter(Collider 2D WhateverYouWantToNameIt) {
if (WhateverYouWantToNameIt.tag == "your moving platform tag")//(casesensitive)
//do stuff to add the x&y movements of the platform to you
}
}
Answer by b1gry4n · Oct 13, 2016 at 02:19 AM
You are working in 2d, so dont forget that. Whether it is top down, side scrolling, etc...it is still 2d space. This means that the rooms on the sides/above/below could just as easily be walls surrounding a room from a top down view. The art would be the visual cue that we are playing a sidescroller rather than a top down.
You could use a rigidbody for gravity, or you can simulate your own for more control (though gravity is a pretty universal thing)
To simulate gravity, just apply a force in the direction you want the gravity to take effect. Cast a ray from the players position "down". Use colliders on a ground layer of your choice. If a ray of a certain length (usually a length that ends a tiny bit below the characters feet) hits the ground collider, you are grounded. If not, apply the simulated gravity force.
I havent done a lot of 2d work inside unity, but I do know that unity has a whole collection of tools available for 2d games.
https://unity3d.com/learn/tutorials/topics/2d-game-creation/rigidbody-2d?playlist=17093 https://docs.unity3d.com/ScriptReference/Physics2D.Raycast.html https://unity3d.com/learn/tutorials/topics/2d-game-creation/collider-2d
Answer by MerlinsMaster · Oct 13, 2016 at 02:50 AM
This video will show you the way most people doing 2D sidescrollers handle moving platforms:
https://www.youtube.com/watch?v=HMZnSZswTmU∈dex=23&list=PLiyfvmtjWC_Up8XNvM3OSqgbJoMQgHkVz
The series this video is a part of is pretty good if you're just trying this kind of thing out for the first time.
Your answer
Follow this Question
Related Questions
How to turn off gravity? 4 Answers
Horizontal attraction? 0 Answers
2d planetary gravity 3 Answers
Is it possible to have a vehicle stick to a platform when it flips? 1 Answer
Have rigid body enter a planets orbit but always be able to escape it 1 Answer