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 / How should I simulate an aeroplane (2d with v-joystick)

Author
Message
easter bunny
11
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 10th Apr 2013 04:51 Edited at: 10th Apr 2013 06:36
I've started on it and it's going alright, my main problem is that the plane sometimes turns the long way, I get the angle from the vjs(VirtualJoystick).
here's my code, can anyone help?


note: the game is basically a port of AirStrike

Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 10th Apr 2013 09:45
i think you mean you want turn from 350 degree to 0 and it turns 350 degree instead of 10 degree?
easter bunny
11
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 10th Apr 2013 09:50
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 10th Apr 2013 12:19 Edited at: 11th Apr 2013 10:15
edit:
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 10th Apr 2013 16:02
Maybe an idea to work out the angle difference between the current angle and desired angle - so it would be able to adjust the angle gradually rather than trying to be exact. Depends if your project will allow for that, with gameplay I mean.

Like, once you have the joystick angle, get the sprite angle as well, and come up with a modification value and apply that to the sprite angle. I find this sort of gradual movement more pleasing - like instead of:

if you.rdir < you.dir then you.rdir = you.rdir + 5
if you.rdir > you.dir then you.rdir = you.rdir - 5

you might have:

diff#=you.rdir-you.dir

Now that's an angle, but without correcting for wraparound, so to fix that:

While diff#>180.0
diff#=diff#-360.0
Endwhile

While diff#<-180.0
diff#=diff#+360.0
Endwhile

Now diff# will be a value between -180.0 and 180.0 that you can apply to your you.rdir value to get the same instant movement. But if you limit it, you get gradual movement, like this:

If diff#<-3.0 then diff#=-3.0
If diff#>3.0 then diff#=3.0

Now it'll only rotate by a maximum of 3 degrees each frame.

So something like this, untested, but along these line:



I got a fever, and the only prescription, is more memes.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 10th Apr 2013 22:42 Edited at: 10th Apr 2013 22:46


easter bunny
11
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 11th Apr 2013 04:04 Edited at: 11th Apr 2013 06:10
thanks Van B, that works well.
Here are some of the functions I use in case anyone else finds them useful:

I've attached a zip of where the flying is going so far, I need to make the air resistance mode realistic, but apart from that I think it's pretty good.

Attachments

Login to view attachments
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 11th Apr 2013 10:14
That's pretty cool! - nice smooth movements, perfect for this sort of game. I haven't played AirStrike, but what I've seen it seems pretty cool. What I find strange though is how it isn't done already! - like several people are making it at the same time apparently... yet here's one person armed with AppGameKit getting it done.

I got a fever, and the only prescription, is more memes.
DennisW
15
Years of Service
User Offline
Joined: 15th Jun 2008
Location: Ohio
Posted: 11th Apr 2013 17:37
Very Fine indeed I liked it. Looks very promising.

Ham and Eggs Breakfast
The Chicken was involved the Pig was Committed
AGK Community Tester

Login to post a reply

Server time is: 2024-05-04 07:56:45
Your offset time is: 2024-05-04 07:56:45