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 Classic Chat / Player Movement with Acceleration

Author
Message
Steveotronic
9
Years of Service
User Offline
Joined: 8th Feb 2015
Location: Leicestershire
Posted: 17th Mar 2017 23:00
Hi everyone,

I have searched the forums but can't find any mention of it, just wondering how I would accelerate a players movement (i.e. from 0 up to a maximum of 4 ) using Tier 1 instead of them just going from 0 to 4 instantly.

just something I want to try to add to the game feel.

Any help would be appreciated, also if I have overlooked something from the forums I apologise, but after a few days of trying things followed by a few days of searching the forums and the web I still can't get my head round it.

Thanks.

Steve
Increase
7
Years of Service
User Offline
Joined: 21st Feb 2017
Location:
Posted: 18th Mar 2017 13:27 Edited at: 18th Mar 2017 13:32
x = the usual speed per frame - in this example, the x-axis acceleration of the line

increase = the speed which is added as long as a button is pressed ( in this case mouse or touchpad)

if the button is released, the increase component decreases, but can't get lesser than 0 to not infere with the origin speed.


Steveotronic
9
Years of Service
User Offline
Joined: 8th Feb 2015
Location: Leicestershire
Posted: 18th Mar 2017 23:04
Thank you,

I have had a play around within my code and got it working to my liking. Thank you again.

I appreciate the speed with which you replied.

Hopefully I can show something soon.

Steve.
GameDevGuy
9
Years of Service
User Offline
Joined: 18th Jul 2015
Location:
Posted: 19th Mar 2017 09:32
Here is an outline of the type of code I would use:



This is only in one dimension and there is no slowing down, the sprite will disappear off the right edge of the screen.

The actual numbers that will look good will depend on the frames per second.

The value of mySpriteAccelerationX sets how fast the sprite speeds up, but it will never travel faster than 4 pixels per frame from a standing start.

Similar ideas can be expanded to handle movement with a y component, but once you have diagonal movement the code becomes more complicated as there needs to be a calculation of the distance between the start and destination, if you need to ensure that the total speed remains no more than 4.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 20th Mar 2017 08:53
I'd do it like this...
Signature removed by mod because it's larger than 600x120... please resize and try again.

Login to post a reply

Server time is: 2024-09-30 01:40:49
Your offset time is: 2024-09-30 01:40:49