Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / Platformer - Smooth movement?

Author
Message
subratabera
2
Years of Service
User Offline
Joined: 7th Apr 2021
Location:
Posted: 19th May 2021 18:56
Hello everyone! I am very new to AppGameKit Studio and trying to learn the basics by following various tutorials and examples.

While creating a sample platformer level, I found that the movements are not very smooth. One example is, the player sticks to the sides of the platform while moving left or right. I wonder how I can improve the overall experience and make things snappier.

Any tip on handling the background and platform objects would be really helpful.

Please find the project files attached for your review and suggestions. Any help would be highly appreciated.

Attachments

Login to view attachments
Dualunitfold
4
Years of Service
User Offline
Joined: 13th Oct 2019
Location:
Posted: 19th May 2021 21:34
Hello
I've never used the AppGameKit physics engine in my life, and I've tried and failed to make platformer physics myself, so I'm probably the least qualified person to answer this, but I do have a few ideas I can bounce around that may or may not be useful

So my thinking as to the reason your character jerks sideways from the centre of the screen when you move is that you're using the sprite's position to position the "camera", and the sprite's position only gets updated by the physics engine during the Sync() command, which is after you set the "camera" position.
I fixed this pretty easily by splitting Sync() into its components: Update(1.0/30), Render() and Swap() (1.0/30 because that's what your fps is set to). Then I put your SetViewOffset() command after Update() but before Render(), so all the positions are up to date before it renders.
That's almost certainly not the best way to do it, because like I say I haven't used the physics stuff before and don't really know what I'm on about

In the name of smoothness, I would normally not set an object's velocity directly, because nothing works like that in real life. Instead I would probably have a cap velocity so it doesn't end up going super fast and then instead of setting the velocity to that straight away, just increase it by a certain amount each frame until it reaches that cap velocity. This should make it feel less jerky, if that's what you were looking for.

About the sticking to walls thing, that's probably because they physics engine wants to set the velocity to 0 or thereabouts when it hits the wall, but you then set it straight back to what it was, meaning that it's kinda being pushed into the wall. That's my best guess anyway. Doing my previous suggestion might fix this to an extent, because the velocity would at least only get increased by one increment by your code instead of the full amount. Alternatively, you could have similar variables to your isonground one, but for the walls. This would be tough because of the thinness of your platforms, a single raycast thingy wouldn't be able to tell, for example, if just the character's head hit the wall, or just its feet. I guess you could do multiple raycasts or something? I dunno.
But then if you has isonleftwall and isonrightwall or something, you could use these variables to make sure pressing the right key doesn't set the character's velocity to 500 or whatever if it's already touching a wall on the right hand side.

Another thing to watch out for is that your raycast for touching the ground only works in the middle of the character, so you it won't let you jump if you're overhanging the edge by more than half.

Well there you go, some ideas from me. They might all be useful, or none of them, I don't really know, you (and possibly others who critique my methods) decide
Hope you work it out!
subratabera
2
Years of Service
User Offline
Joined: 7th Apr 2021
Location:
Posted: 20th May 2021 13:46
Thank you Dualunitfold. Those are some really useful tips. I'll certainly try them.
ruckertheron
7
Years of Service
User Offline
Joined: 12th Nov 2016
Location:
Posted: 3rd Jun 2021 23:23
I can help. What exactly are looking for? up and down collision? left and right? Let me unzip your project and see what I can point out.
ruckertheron
7
Years of Service
User Offline
Joined: 12th Nov 2016
Location:
Posted: 4th Jun 2021 00:11
Oh never mind... your using the in game physics
jd_zoo
5
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 4th Jun 2021 01:51
I'm not quite sure but you may need to look at using forces for this. But depending on what you are doing a SetObjectPosition(objID, GetObjectX(objID) + X, GetObjectY(objID) + Y) is how I approach simple 2D controlled movement.

https://www.appgamekit.com/documentation/Reference/Sprite/SetSpritePhysicsVelocity.htm

Also I haven't used the scene editor for something like this, but I might be tempted to set up your platforms as static objects and then the jumper guy as dynamic, then use forces to move him around.

https://www.appgamekit.com/documentation/Reference/Sprite/SetSpritePhysicsOn.htm
https://www.appgamekit.com/documentation/Reference/Sprite/SetSpritePhysicsForce.htm

@ruckertheron - why wouldn't you use the in game physics??
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 4th Jun 2021 03:54 Edited at: 4th Jun 2021 07:13
i did have a look at the code but since it's Studio, making changes to physics settings for sprites in the scene editor is more than a chore (especially the sliders when you're just trying to tweak something vs bashing it).

but, i will say this. the changes you've made from the default settings (starting with scale & gravity) are drastic:

ie, you've cut the scale from 0.2 to 0.05 and then feel the need to compensate for it by setting gravity to 1500.

i know how trying to tame box2d can feel, believe me. but, i've learned to "massage" settings, and as few as possible, and let box2d do its thing while trying to understand what the various settings actually affect.

ie, you have linear dampening set to 1.633 which, i assume, you've set because you want it to slow down quicker when moving side to side. but, it's also why you "need" such a high gravity setting to force a "reasonable" fall rate (trying to compensate for the dampening that you've set. aka, the "obstacle" that you've actually presented).

a couple suggestions:

check out SpecTre's code in the small games templates thread as i remember it being a good example of a platformer under box2d. the thread is a mess (and, since the parts i want to edit are Ricks, it won't let me modify) but there are gems inside. if you have Games Pack 1, all of the templates from the thread are there (and more - the $5 price tag is worth the code examples. even more-so when it's on sale ).

otherwise, if you truly want to dive into a rabbit hole. i spent a 3-day weekend deep inside and, tho exhausted, came out the other side with a better understanding of it all. it's a chore dealing with (the original) terminology but things will make sense eventually

sorry that this is a long-winded indirect/non solution but it really is my best advice

ack! so, i've revisited SpecTre's code and it seems you've already found it and abused it some. and, it also reminded me that it had issues. then, there's THIS where he opted to write his own physics system (which predates the template code?). regardless, you might find some insight.
[My Itch.io Home] [Community Apps on Itch.io]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=agk] YOUR CODE HERE [/CODE]
[VIDEO=youtube] VIDEO ID [/VIDEO]
[AGK Showcase][Google Forum Search]

Login to post a reply

Server time is: 2024-03-29 10:31:22
Your offset time is: 2024-03-29 10:31:22