I am doing a group project as an assignment. We are making a 2.5D sidescroller (Please don’t ask me why, not my decision)
Anyway I am new to unity so I don’t want the code, just a point in the right direction on the best way to implement the following.
The character moves along the x plane (obviously) but there are 3 of these (apparently it is similar to the game Little Big Planet).
At certain points (I have named these crossPoints) the player can cross to the adjoining plane.
So the player can move with the forward and back arrows and nothing happens if pressing the up and down, unless he is parallel to the crossPoints (think doors). In that case he will move to the other plane.
If in the middle plane I need to know which side of the player the crossPoint is on (i.e. - or + I guess).
What is the best way to implement this? Is it with colliders (if so, how do I know which side?) or is there a better way.
Any advice is greatly appreciated, I’m here to learn as much as i can.
2.5D … “Please don’t ask me why, not my decision” LOL !!!
if you really mean 2.5D, 2.5D games in Unity are very often made with 2DToolkit. get it in the app store. (it would be an astoundingly, completely ridiculous waste of time, to write 2 man years of code to handle sprite sheets, etc) other similar competing packages exist too
just FTR as far as I know Little Big Planet is an entirely 3D game (you see all the models in 3D, not orthographic), it just happens that the camera is usually at one side
…the x plane (obviously)… in Unity if you are standing up at the racetrack looking forwrd. x and y are exactly like in junior high geometry. Y is up and X is to your right. z is forward. it is a “z forward” universe. you will say this phrase 900 billion times in your career. you hire someone to make some models, you tell them “don’t forge it must be z forward”
typically you do a 2.5D game in the XY plane. ie standing up. (so that gravity works of course) so the action happens at z=fixed value. if by “x plane” you meant the “YZ” plane that is not really right, you do it in the z plane (ie, the XY, upright, z=0, plane)
i say typically in the sense of “you basically must do it that way, there is no other possibility” so if you’ve done the game laying down or sideways, you’ll have to change it immediately before going further
your question … you will have to draw a diagram. it’s confusing.
but I think all you hae to do is simply look at the position of the hero. so that’s hero.transform.position.x. if that value is less than 12.45 (or whatever) you know he is on one side, if more than 12.45 he is on your other side. it’s that simple.
(note that I say x because x is moving left and right in a 2.5D side scroller. y is moving up and down - exactly like drawing a cartesian graph in junior high … on the iPad screen, x is left and right and y is up and down)
a collider … those do not really let you know WHERE SOMETHING IS, more WHEN IT ENTERS AN AREA. makes sense?
to find out “where something is” you incredibly simply define an area (I mean like “x is between 1.2 and 1.87” and “y is between whatever”) and then you use an “if” statement to see if the thing is in that area.
in fact often you’d simply have a tiny script (one line) attached to the object that constantly sets a boolean, in or out of area. then at any moment you can just say isItInsideThe.danegrZone at any time.
if you need more than this, need a diagram !!
you asked for actual code!
say you have a DOG and you want to know which side it is from a TREE. ok?
var DOG:Transform;
var TREE:Transform;
var distanceToRight:float;
distanceToRight = DOG.position.x - TREE.position.x;
if ( distanceToRight > 0.0 )
Debug.Log("the dog is on the right of the tree !!");
else
Debug.Log(the dog is left of the tree.");