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 / Help with gravity

Author
Message
Spadey
8
Years of Service
User Offline
Joined: 5th Sep 2016
Location:
Posted: 5th Sep 2016 17:06
Hi,
I'm new to AppGameKit and have a question that I hope someone will be able to help me with.
If you look at the attached image I have created a 2D maze where a ball drops in from the top.

I have applied gravity to the ball but what I want is when the ball hits a flat service (wall) of the maze then it will continue moving to the left (or right) until there is space in the maze to fall down the next level (think Donkey Kong but without sloping platforms for the barrel to roll down), so the ball will always reach the bottom of the screen. At present using gravity the ball just stops at the first wall and stays there because the wall is straight and not on a slope.

I hope i'm explaining this well enough, I originally coded without gravity to check if the ball collides with a wall then to force a direction change an re draw the sprite but I think using gravity would be a much better way of doing what I want.

Hope someone can help me with this.

Thanks
Richard
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 6th Sep 2016 08:36
Can you share your code or maybe an image?
Using AppGameKit V2 Tier 1
Conjured Entertainment
AGK Developer
19
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 12th Sep 2016 23:59 Edited at: 13th Sep 2016 00:17
You will need too apply a force (SetSpritePhysicsForce) to the sprite (ball) to make it move left or right on a flat surface.
The gravity is pulling straight down on flat surfaces without other forces, so you have to push it left or right on flat surfaces.
Don't forget to SetSpriteShape to a circle (1) so it can roll.
I use SetSpritePhysicsVelocity if I want a bounce too, when changing direction after hitting a side wall.

You can use a variable for the amount of force, and multiplying that by -1 would allow for a single force call to work both directions.
You would apply a positive value for the variable to roll until it hits a side wall, then multiply that by -1 when hitting the wall to make it a negative value to roll the other way.
Then when it hits a side wall rolling in that direction, it would again multiple the force variable by -1 to change it back to a positive and roll the other way.
I hope this explanation make sense, because I don't have a snippet to share.

Your image attachment doesn't seem to be here, so you may want to try uploading it again, or post a code snippet.

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1

Login to post a reply

Server time is: 2024-11-22 04:00:20
Your offset time is: 2024-11-22 04:00:20