|
|
|
|
Reply From: |
batmanasb |
Here’s a simple demo of how to make ladder blocks using either StaticBody2D or Area2D nodes. In this demo I didn’t make a tileset, but just made and duplicated ladder nodes. However, the concept is the same and it’s simple to make tiles the same way.
Hi batmanasb, I ran the demo but nothing really happened, I could only see text. I guess this was more of a demo concept? As I could only see collision nodes and no sprites.
I’m looking over what you’ve done now, trying to figure out and peice together what you’ve done. Then hopefully I can apply something similar to my project. I’ll let you know how it goes.
And like always, thanks for replying
EDIT: I added my own sprites to what you had done and now I can see your demo works perfectly. Now to try and do the same for mine!
Gotta learn to read README files
It said to enable “Visible Collision Shapes” when you run the demo.
batmanasb | 2016-03-28 17:38
Just curious though (I’m about to start to do it now), I have a RigidBody2D as my main node for my player. I see in your code you used a KinematicBody2D. I guess for this to work correctly for mine, I’ll need to change mine from RigidBody2D to KinematicBody2D?
Yeah haha, sorry about that. I guess I rushed ahead, my mistake!
EDIT: Trying to change from Rigid to Kinematic brings up all sorts of errors about non supported functions. What a headache!
If there is a way to do this using RigidBody2D that’d be amazing
Well, the thing with RigidBody2D nodes is that they are complicated to control. You have to use impulse and stuff. KinematicBody2D nodes are much simpler to use for player controlled characters but you have to handle all the “physics” yourself. Like how I did gravity in the demo. I’m not even sure how you would put a RigidBody2D on a ladder, maybe overriding the gravity vector?
But to answer your question, you can still attach a Area2D to a RigidBody2D and it’ll work just fine. Only issue with that is controlling the character.
batmanasb | 2016-03-28 18:08
More great news haha!
I replaced my RigidBody2D node with a KinematicBody2D one. Then I proceded to delete some of the code that was dependant on the RigidBody2D and replaced it with some of the code you provided in the demo. It ran, but there was some weird occurances, such as the fact the player slid all the way to the bottom of the map and if he went in one particular direction eventually he would slow down and the reverse and head in the opposite direction.
So, I guess I’ll have to try and implement this using the RigidBody2D approach. If this doesn’t work, I’m going to cry!
Thanks again for your continuing help!
Hi batmanasb.
Sorry to bother you again. I’m still having trouble and at this rate I don’t think I can fix this by myself. I’ve implemented most of your demo in my own little game, but it’s not quite working yet.
Obviously you’re alot more experienced with Godot than I am. I know it’s alot to ask but I was wondering if you’d be able to take a look at my project, see what the problem is and fix it. I usually don’t admit defeat but I’ve tried to get this working for hours! If you could help me reach this last step it would be greatly appreciated.
Thank you for taking the time to assist me in this problem so far, it’s greatly appreciated!
yeah sure, just post a link
batmanasb | 2016-03-29 00:24
Thank you.
I’ve uploaded the files to my dropbox: removed
Some of the code might be a little muddled as I was experimenting, hoping to figure out a way to do it. I hope you have more success than I did.
If you manage to resolve it, I’d love to know what I was doing wrong. Again, thank you!
“fixed”
Okay so it looks to me like you are trying to use a RigidBody2D node as if it was a KinematicBody2D node. You’re not supposed to be setting the velocity of a RigidBody2D manually, but instead apply a force or an impulse on it. (aka give it a push) Setting the velocity every frame kinda messes up the physics and the point of using the physics in the first place. So I’d recommend switching to a KinematicBody2D since you are moving the character as if it were a KinematicBody2D anyways, but this way it’ll be less buggy.
But disregarding all that, when you copied over my demo code, you didn’t fully integrate it. You were setting the “velocity” variable but not using it. All I did was change it at around line 88, where I just set the velocity of the RigidBody2D using set_linear_velocity
to a negative Y value, this way he goes up. I think you mixed up the variable “velocity” with the actual velocity of the character that’s built into the RigidBody2D node. But yeah, now he goes up ladders, but now you need to clean up the code a little and polish it. A few suggestions would be to set the X value in the linear_velocity to 0 while climbing so he doesn’t slide off ladders, and set the velocity to (0,0) when climbing but not pressing a key so that he doesn’t fall off the ladder when not holding Up or W.
batmanasb | 2016-03-29 13:48
Thank you so much for helping me with this problem! You’ve helped me a great deal and I appreciate the time you’ve taken to assist me with this, it means a lot
You were correct about me getting the velocities mixed up, I was tired at the time, trying anything to get it to work. Thank you for your explanation, it’s easy to understand.
Hopefully now I can clean up the code a little bit, make a few fixes as you’ve suggested and then do this for every set of ladders in my game. Wooo! Thanks again
Hi batmanasb.
I’m really sorry to be a nuisance but I’ve been trying to implement those fixes you suggested but I haven’t had any luck with them. I’ve tried to do what you’ve said in your description but it ends up quite being quite wrong.
For example, the part where you suggested to set the velocity to (0,0) when climbing but not pressing a key, I tried to do that but instead when the player hit the ladder he stopped and then he couldn’t move after that.
And me trying to set the X value in the linear_velocity to 0 while climbing so he doesn’t slide off ladders, didn’t accomplish anything.
It’s quite frustrating really, I know exactly what you mean but I just can’t figure out the code to in order to implement it properly. The sooner I put this ladder business behind me, the better!
I’m a bit hesitant to ask for your help as you’ve already been really helpful with everything else, I just figured seen as you suggested those two things you’d be able to help me finally fix this.
Sorry in advance if I’ve bothered you.
I meant set the Y velocity to 0 when on the ladder but not pressing any key, that way you won’t fall off the ladder, but can still move in the X axis (left and right). Also, when climbing up (pressing UP) it might help to disable left/right movement so that you don’t slide off the ladder. So setting linear_velocity
to (0, climbingSpeed) should do that. Both these things are in my demo. But I think your real problem is dealing with a RigidBody2D node, they are awkward to control and only really useful when your character is physics based, which no Mario character ever was. If you’d switch it to a KinematicBody2D node, then you can follow the demo so much easier. Besides, using set_linear_velocity
for movement is considered sloppy code as it messes up the physics.
batmanasb | 2016-04-01 18:38
Can you please reupload the demo
everancii | 2016-12-23 22:55