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.

Android / Force/Impulse/Velocity/Gravity/Mass - aka Physics

Author
Message
ApkGames.Guru
10
Years of Service
User Offline
Joined: 25th Oct 2013
Location: England, UK
Posted: 15th Mar 2014 14:16
Hi.

Has anyone mastered this? I'm trying to get a ball to fire out of a cannon. As soon as a button is clicked, I issues the impulse command to set the X velocity and no matter what I try, even with a parameter for speed/distance, the ball just travels the same length. I understand it's affect by gravity and mass, but as these values are not changing, I was expecting the bigger the X value passed to the impulse command, the faster/further the ball would travel?

Has anyone mastered this and maybe can provide a pointer, code snippet etc to help me move this along

I'm using Basic language for this.

Cheers, Ian.
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 15th Mar 2014 14:56
Have you got something you can up-load? Sometimes with physics (box2D or coding your own) it can be a case of juggling the values to get things to look right. There might be some values that need to be a lot higher or a lot lower than what you have at the moment.

ApkGames.Guru
10
Years of Service
User Offline
Joined: 25th Oct 2013
Location: England, UK
Posted: 15th Mar 2014 15:44
Yeah, here we go.

SetPhysicsGravity( 0, 250)
SetSpritePhysicsOn(Acorn,2)
SetSpritePhysicsMass(Acorn,55*MassMult#)
SetSpritePhysicsRestitution(Acorn, BScale#)
SetSpritePhysicsImpulse(Acorn,GetSpriteX(Acorn),GetSpriteY(Acorn),(SScale#*MassMult#)*BScale#, -1)

Variables MassMult# is a value of say 1.1 to give the ball some strength when it collides with something else.
BScale# is the bouce value, how much I want the ball to bounce, typically a value of .9
SScale# is the force, so what speed I want.

It's SScale# that I'd like to set between a range of 1 to 10 and if a 1 the ball just drops, but a 10 it arcs to other side of the screen, and if a 4 for instances, drops short of mid-way.

Any advice is welcome.

Thanks, Ian,
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 18th Mar 2014 21:19
I've come up with a little demo program:



The values you want to play around with are setPhysicsGravity and the variable ball_initial_speed#.

Low values of gravity and ball_initial_speed# with give a light, floaty trajectory. Higher values of gravity and ball_initial_speed# will give a faster trajectory. The trick with a game it is to juggle the two value until you get something you're happy with.

A low initial speed and high gravity will cause the ball to drop but not go very far horizontally.

A high initial speed and low gravity will cause the ball to go in a straighter line.

In this example, changing the mass of the canon ball won't effect the trajectory as I'm just setting the ball's velocity. If you used a impulse force then the mass would effect the initial velocity of the ball as the impulse force would have more to push against (hope that makes sense).

Restitution will simulate air resistance, i.e. it will slow the ball down, but it won't simulate wind (i.e. the wind could cause the ball to move back toward the canon).

There's a whole bunch of other things you can play about with depending on what the canon ball is hitting but I'll leave that for now.

One other thing, this thread should have gone on the general AppGameKit board as this board is just for Android related issues, and you probably would've got more responses. I expect if you email or PM a mod they'll move it for you.

Hope this helps.

ApkGames.Guru
10
Years of Service
User Offline
Joined: 25th Oct 2013
Location: England, UK
Posted: 4th Apr 2014 15:24
This is great. Many thanks for putting time into this. I will take and adjust where needed.

Thanks again, Ian.

https://play.google.com/store/search?q=zortok&c=apps
micky4fun
10
Years of Service
User Offline
Joined: 15th Sep 2013
Location: uk essex
Posted: 11th Apr 2014 22:21
Hi Stormforce ,

I have downloaded a few games of yours from the store , which I will rate shortly, not knowing anything about you and being new to AppGameKit app , I am wondering is it AppGameKit app you are using for you games on the play store , I am now trying out this app to hopefully write some game , the being still quite a novice I have written a few games using Playbasic , of which for foxs sake being my best and latest , can be found by typing for fox's sake game in google

thanks
mick
ApkGames.Guru
10
Years of Service
User Offline
Joined: 25th Oct 2013
Location: England, UK
Posted: 22nd May 2014 13:52
Hi Mick,

Yes, AppGameKit (basic) is what I use to create the games. I'm from the QuickBasic/VisualBasic days.

Ian.
micky4fun
10
Years of Service
User Offline
Joined: 15th Sep 2013
Location: uk essex
Posted: 1st Jul 2014 11:15
Hi All

Stormforce
sorry for late reply , see you have been very busy tapping away with AppGameKit , some nice varied games you have in your collection
I am a basic person myself started with Playbasic , good program but wanted to do some android app stuff and that does not support it , will keep an eye out for your apps

mick
ApkGames.Guru
10
Years of Service
User Offline
Joined: 25th Oct 2013
Location: England, UK
Posted: 10th Jul 2014 14:14
Thanks Mick, appreciated.

Login to post a reply

Server time is: 2024-02-23 20:13:56
Your offset time is: 2024-02-23 20:13:56