I can't get my movement in the air quite right?!?
Hi guys,
I was wondering if anyone could help me out. I have an issue that I cant seem to resolve.
I have a 2d platformer game that I have set up. The main character has all the usual rules including movement left, right and also a double jump. The character moves fine and you can control his movement left or right while he is in the air both jumping and falling.
The issue I have is when he collides with a platform in the air the x movement is then stopped meaning I have to let go of touch/key and re-press it.
So for example If I hold down right and hit jump the character moves right and jumps while still moving right throughout the jump until i release the button. However if I am standing directly next to a platform hold down right and then jump the character jumps and doesn't move right even when its Y position is above the platform. I would expect that because I am holding right that once I have jumped and the character is above the platform that he would then move right automatically and land on top of it. so at the moment I can't hit right until the character is above the platform which feels very unnatural.
I hope you understand what I mean and that this is an easy fix.
I am using linear velocity to control movement for right, left, jump and gravity. I have tried playing with accelerate/accelerate towards but he then speeds up to much and I can't control this by using max speed as this would be lower than the speed I have set for him while jumping.
Kind regards
Comments
Can you show a screen shot of your movement behaviours ? or type them please
Hi Icebox.
Below is the rules I have set up for moving right (left is obviously just a reverse of this).
I have it set so that I move right when " game.moving right " is set to true as I am using touch buttons on my HUD and not keyboard keys
Below Is Gravity
And below is my jump
Again the jump is operated by a game level attribute so that I can use touch. I have also tried to play around with touch pressed, touch inside as well as trying different timers and interpolation rules. Nothing seems to do what I need to it!!
Replace change attribute with constrain attribute
so instead of change attribute self.motion.linear.velocityx to 250
make it constrain attribute self.motion.linear.velocityx to 250
This should probably work , not sure though , tell me if it does.
It did work thank you!
I read and watched so many tutorials and not one person used constrain over change and yet the movement is now perfect! I can't begin to tell you how much time I have spent trying to solve this and how much more time you have just saved me!
Can't thank you enough!
Thats awesome , you welcome !
I know its frustrating in the beginning but once you understand how each behaviour work , things will become much easier . So if you want to learn more about why it works this way.
In your case, when you press right it will change velocity to 250 and thats it . The only way to trigger it again is to press right again.
So when you hit a wall your velocity changes to 0 , the only way to change it back to 250 is to press right again , thats why change attribute caused you trouble , look at this example
Change attribute example
But when you constrain the speed to 250 , even if you hit a wall , it will constrain the velocity to 250 , 60 times a second , it will never stop unless you release the right button. So the actor is trying to change the velocity to 0 but your forcing it/ constraining it to 250 no matter what happens.
Constrain attribute example
Hope this helps you in the future , just to get a better understanding of how change attribute and constrain attribute work , and always try to use display text to debug and know where the problem is . Gamesalad members are usually very helpfull so use the forums whenever your stuck. Good luck !
Good explanation.