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.

Newcomers AppGameKit Corner / [SOLVED] Sprite movement with inertia by default

Author
Message
okasion
5
Years of Service
User Offline
Joined: 4th Oct 2019
Location:
Posted: 8th Oct 2019 21:16
Hello guys, I purchased (!) AppGameKit Classic the other day on Steam, because it was cheap enough to me, Unity worked too slow and Godot did seem too big for my current needs.
I am trying to make a Touhou-like demo (think of a 2D shooter but with anime girls instead of spaceships). So far everything is working pretty great, for example, the collision between the boundaries of window worked super easy.

My problem is that, when using:
playerx=playerx+GetDirectionX()*4
playery=playery+GetDirectionY()*4

the sprite seems too get some little inertia, which would be very nice for any other project, but not for games which demands a lot precision such a Touhou-like games.

This is what it looks like by now


Thanks in advance.

The author of this post has marked a post as an answer.

Go to answer

Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 9th Oct 2019 17:20
This post has been marked by the post author as the answer.
GetDirectionX and GetDirectionY() are designed to read phones accellerometer (what angle the phone is being held at). Its not designed for very large changes in values quickly or to read keypresses imeadiately.

If your run it on PC then it approximates an accelerometer input using a smoothed (slewed) version of the arrow key inputs so you can test on a PC which doesnt have an accelerometer. These values change slowly so you can approximate an analog input on a digital keypress.

The joystickinputs (GetJoystickX()) are also slewed when there is no joystick connected and so WSAD keys are used and the value slowly changes.

If you just want to know if the keyboard arrow keys are pressed they use GetRawKeyState()

Eg...GetRawKeyState(37) =1 when the left arrow is pressed

KEY_LEFT 37
KEY_UP 38
KEY_RIGHT 39
KEY_DOWN 40

so

playerx=playerx+(GetRawKeyState(39)-GetRawKeyState(37))*4
playery=playery+(GetRawKeyState(40)-GetRawKeyState(38))*4

will give you movement from the arrow keys which is immediate and doesnt have acceleration.

You should also consider timer based movement to compensate for varying frame rates.

okasion
5
Years of Service
User Offline
Joined: 4th Oct 2019
Location:
Posted: 9th Oct 2019 21:53
Bengismo wrote: "GetDirectionX and GetDirectionY() are designed to read phones accellerometer (what angle the phone is being held at). Its not designed for very large changes in values quickly or to read keypresses imeadiately."

I never read this since I began working on AppGameKit; I knew it had support for phones but I didn't though it intrinsically would come with functions modified to work on them. I ended up using this simple and amazing tutorial [video=https://www.youtube.com/watch?v=KAGNuwBEc1w]
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 10th Oct 2019 02:05
If you are after some inertia with friction effects
this example of a menu might help (I hope you can understand my code )
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 10th Oct 2019 09:19
fubarpk wrote: "If you are after some inertia with friction effects"


He was actually trying to get rid of the inertia effects.

The GetDirectionX/Y() commands actually add a sort of inertia affect because the input values they supply from the keyboard are smoothed and so they change slowly (typically 2-3 seconds to go from 0 to 1). Key inputs or actual joystick inputs would give an immediate response rather then a damped/slow one.

Login to post a reply

Server time is: 2024-11-23 09:33:34
Your offset time is: 2024-11-23 09:33:34