- Home /
How do I do movement in a Beat Em Up? (2D movement w/ jumping in a pseudo-3D environment)
I am seriously at my wits end with this. I'm extremely frustrated right now, so pardon the anger.
I can't figure out how to do this to save my life. I've tried everything; I've tried tilting the walkable area and making the game 3D, but the damned polygon colliders for my backgrounds won't tilt with them. I've tried making a parent and child rigidbody (the parent for the "shadow" and the child is the sprite which jumps, so I always have a spot on the ground to reference when I jump to check to see if I've hit the ground), but not only have I read that this is extremely poor practice, the damned child body, for some reason, can't pick up the parent's speed to adjust my animator. I've tried to maintain a separate vector for the "ground position" but, in the presence of colliders, these values are not correct. Furthermore, if I print these two values together, the maintained vector eventually accumulates error. I can't pull these numbers off the rigidbody because the jump throws off the correct y value for the ground. My last recourse was to implement gravity manually, but I don't want the rigid body to be kinematic. I feel like I've seriously tried everything, and I'm on the verge of giving up. I just can't get the damned thing to run correctly.
Please, if anybody has made a 2D beat em up, please help me. I haven't been able to find any good information for how to make this work in Unity, and I'm starting to think it just won't work. If there is any advice, I am sure it will be invaluable to others who are foolish enough to go down this path.
The learning curve in Game Development is a steep one to be sure! I don't blame you for being frustrated- I've been in your shoes more often than I'd like to admit.
For starters, I'm a bit confused by exactly what "Pseudo 3D" means. $$anonymous$$aybe you could add a link to a video of a game showing what you want to do?
jcsiezmo im doing a beat em up like that but i cant find how to move in z over the plane how can i move the player in a plane 3d if is 2d i hope you can help me becouse i find evething about plataforms but no about beat em up
thanks
I'm working on a 2.5d game as an amateur beginner, if you still need I can tell you more about how I'm handling movement in its 3d environment. Though it might look like a simple task, moving sprites decently in a 3d space has some tough issues to solve, mainly because Unity is set up to either handle 2d or 3d, not a mix of the two ( my humble opinion here). Hold on and don't give up pal!
P.S.: I too believe that keeping your dudes separated from their shadows is not a good idea, but a workaround could be possible ( I'm not using shadows in my project BUT when I parent player and camera everything works like a charm, maybe it could help you too).
Again, if you still need some help I can post an answer, let me know :D
well yes i need a hand jajaja some direction will be nice thanks
Allright, sorry to be out of touch for a while guys. I've been working on this, and I think I might actually be on the right track. esitoinatteso, I very much appreciate your advice - I will try your approach once I follow $$anonymous$$e through to its logical conclusion. I'm beginning to consider the approach of moving my sprite completely kinematically, which is what it roughly looks like your approachs does.
This is what I've been able to do:
Create a new GameObject.
$$anonymous$$ake the sprite a child of this game object.
Create another GameObject and make it a child of the empty GameObject. In other words, this GameObject is a sibling of the sprite. This GameObject is the "dummy".
$$anonymous$$ake 2 layers: "Player" and "Dummy". The sprite is the former layer; the dummy is obviously the Dummy layer. Go into your Physics settings and uncheck the box between the Player and Dummy layers.
$$anonymous$$ake a separate movement script, and copy and paste the sprite's movement into this new script. The only exception: the dummy has no jump code.
$$anonymous$$ake sure the RigidBody2D and any applicable colliders are exactly the same in the dummy.
I'm still playing around this with, but with this approach I have effectively separated the jumping from the collider I have around the feet. This has resulted in 2 issues:
If I jump, the collider for the feet has to be turned into a trigger. Otherwise, it collides with anything "above" it.
$$anonymous$$y jumping code has caused the problem of my x velocity to exceed my speed limit, and the collider for the sprite "gets away" from the dummy collider. The intended goal is that the dummy has 1:1 movement with the sprite for the x velocities, and when the sprite comes back down it touches its dummy and the player is grounded once more.
Of course, this 2nd problem also becomes an issue because, if my collider is a trigger, then it no longer obeys my boundaries.
Like I've said, I haven't taken my idea to its conclusion. But, at the very least, I am almost positive I can manually code barriers into the sprite during the jump. I am seeing if I can make sure the dummy is processed first, because then I can pull values directly from its rigidbody. At the very least, I could deal with this issue through kinematic motion although that would require much more maintenance and code to right.
TLDR: There is an approach in the works!
Thanks to everybody who has said anything. I can't wait to get further into my game!
Answer by esitoinatteso · Apr 20, 2015 at 10:22 PM
This is the setup I use for movement, it's borrowed from this Unity game, you can download its assets from the site I believe.
Copypasting the variables declared inside the constructor of the player's class ( give them the value you prefer, I do that inside Awake()):
//Movement Variables
private float xSpeed; //float to give you a x axis speed
private float ySpeed; //as above with y
private float zSpeed; //as above with z
public bool facingRight; //To check if you are facing right or not; note public, this is
//useful when you manually set up the scene and you want
//the player to begin facing Left
This is what I do in Update():
//First, cache input
float h=Input.GetAxis("Horizontal"); //for A D input
float v=Input.GetAxis("Vertical"); //for W S input
float hMove = h * xSpeed; //When input Horizontal is true, multiply h by moveSpeed
float vMove = v * ySpeed; //as above, but referenced to Vertical
float zMove = v * zSpeed; //as above, but for Depth
//... Free the speed from framerate's tiranny...
hMove *= Time.deltaTime; //this shifts the movement's pace to real seconds
vMove *= Time.deltaTime; //as above
zMove *= Time.deltaTime; //as above
//This line tells the game what to do with the lines above, that is to Move.
transform.Translate(hMove,0.0f,zMove, Space.World);
// ... And animate, referencing to absolute values since negatives would be wrong!
if(Mathf.Abs(Input.GetAxis("Horizontal")) != 0 || Mathf.Abs(Input.GetAxis("Vertical")) != 0){
anim.SetBool("MovingInput",true);
}
else{
anim.SetBool("MovingInput",false);
}
//what about flipping? well, if h>0 you're travelling from left to right...
if( h > 0 && !facingRight){
//so you should face right!
Flip();
}
//else...
if( h < 0 && facingRight){
//this is the other way around
Flip ();
}
This makes the player walk around in x/z axis.
I don't have a Jump() function so far, I've got other stuff though. Maybe this can help you: it's one of the many ways one can achieve movement.
The Flip() function is here, this is the coolest thing I've learned digging that game I've linked to you:
void Flip(){
//Many ways to be done, simple one: we swap your bool-facing thing and multiply x scale by -1
facingRight = !facingRight;
//Time to change your scale, best way is doing it with a method that works both ways around as above...
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
//Thanks Unity staff for this trick
}
I'm not sure this is exactly what you was looking for but I hope it helps nevertheless. A word of advice though: it's ok to look chunks of code provided to you, just be sure to also understand their contents and logics... i.e.: copy-pasting is useless without brainpower!
If this is not what you needed, let me know more specifically what is giving you issues, I may know how to help.
P.S.: I forgot to mention that, in order to animate, you need an Animator component and floats declared in that ( I can elaborate this if you need)
i have an issue when the player collite with a wall or something the playe start to moe like moonwalk jajaja from the dirrection you collite the wall ? but everything is ok with this explonation thanks again
Answer by jcsizemo · Apr 30, 2015 at 11:52 AM
My kinematic approach so far hasn't quite panned out the way I would like, so in the meantime I'm attempting to switch to 3D and incorporate an orthographic camera. From a certain angle, jumping and walking up create the same visual effect and the depth is hidden. Of course, my backdrops are somewhat skewed because of this. I'll keep everybody up to date about what I'm doing.
I've run into another problem now, which I will post in a separate thread...
Your answer
Follow this Question
Related Questions
isGrounded is always false, even with gravity, how do you fix that? 1 Answer
Jump Code Not Working (2D C#) 2 Answers
In air movement troubles. 1 Answer
how to stop the camera to follow the player on his jump movement ? 2 Answers
Jet-Pack Script 1 Answer