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 / Angles don't seem to be consistent

Author
Message
JRNTexas
13
Years of Service
User Offline
Joined: 24th May 2011
Location: Austin, Texas
Posted: 27th Oct 2013 03:27 Edited at: 27th Oct 2013 03:35
I am almost finished writing a game. The game is an air hockey game.

So there is a puck (round) that is hit by a "pusher" (also round).


I am doing testing and have noticed that two things are happening. The first is that there are only about 3 angles that can be produced by the puck being hit by the pusher. Is this true? Has anyone experienced this situation? Is there a fix?

I have adjusted the graphics to be sure that they are as round as possible for the resolution and they are both fairly round so that shouldn't be an issue.

The second thing is that when the puck leaves the pusher and it hits the wall, it should always leave the wall at the same angle that it strikes the wall. However, it seems that a particular angle produces a bounce angle that is much sharper than the original strike angle. In fact, the puck almost bounces off the wall at a horizontal angle rather than the sharp angle that it hits the wall with.

This is extremely noticeable since there only seems to be about three angles that can be produced. So, since the effort is to get the puck to go up "ice", that particular angle almost always produces a horizontal reflex rather than going away at the same angle at which it struck the wall.

Any suggestions or help would be appreciated.



I could not originally get the above image to display and reposted it twice more before I realized I could edit this post and fix the problem.
JRNTexas
13
Years of Service
User Offline
Joined: 24th May 2011
Location: Austin, Texas
Posted: 27th Oct 2013 03:30 Edited at: 27th Oct 2013 03:33
/**Removed by author**/
JRNTexas
13
Years of Service
User Offline
Joined: 24th May 2011
Location: Austin, Texas
Posted: 27th Oct 2013 03:32 Edited at: 27th Oct 2013 03:33
/**Removed by author**/
/**Removed by author**/
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 27th Oct 2013 04:44
You can set the physics shape to circle to make sure that it uses an actual circle and not a calculated polygon. That might help with some of the angles.

I don't know if you are experiencing a rotation effect. There are commands related to sprite angles.

Can you show the code being used to make the puck move?

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
JRNTexas
13
Years of Service
User Offline
Joined: 24th May 2011
Location: Austin, Texas
Posted: 27th Oct 2013 10:53
The physics shape is set to circle, for both the puck and the pusher.

When I change the shape to polygon, all results are the same.

There is actually no code that moves the puck. It moves by physics only.

The same is true of vertical or horizontal angles. If the angle is up and down, it is easy for it to become a 180 making it go up and down for ever without changing position until something interferes.

As for the left to right angles, they seem to be altered almost 95% of the time. So that it almost never leaves a wall at the same angle as when it hit the wall.

I thought it might be "gravity" which I have tried to not set anywhere and setting it at different amounts. The more gravity, the more negative effect it seems to have.

I've tried several things to work around the issues but they always introduce new problems.

For instance, I changed the gravity from negative 200 to positive 200 to see if that had any effect and it change it slightly but puck movement began to be unrealistic.

In another instance I used SetSpriteShapeCircle on all of the objects where I was previously using SetSpriteShape for all of the objects. But what happened was the puck hitting wall sound was activated when the puck was 5 to 8 pixels away from the wall and if the puck were traveling vertically in a straight line, the sound was constant and would create noise. If I reduced the radius, the puck would go somewhat past the side (and players) because it did not make contact soon enough.

I didn't start out to write a book but the situation is perplexing.

Again, any help, ideas or suggestions would be appreciated.
JRNTexas
13
Years of Service
User Offline
Joined: 24th May 2011
Location: Austin, Texas
Posted: 27th Oct 2013 10:57
Chapter 2

Oh, and I've also tried preventing the puck from rotating (SetSpritePhysicsCanRotate) to off. Because I thought that the rotation might be putting "English" on the puck, making the after contact angle different from the before contact angle. But this did not help either.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 27th Oct 2013 15:07
Angular physics works fine in AGK. My first suggestion would be the same as AL, you have inadvertently ended up with rectangular/square shapes. SetPhysicsDebugOn() and double check.

The second suggestion would be some rounding error somewhere, if you have used integers instead of floats to intervene with the physics.

Here is AppGameKit Physics in action with 90 circle objects in my bingo game. Jump to 1 minute to see the balls in action.



Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 27th Oct 2013 18:44
Quote: "There is actually no code that moves the puck. It moves by physics only."

I know that you are using physics for the motion. I meant was what command you use to start the movement.

If you have gravity on, that will definitely affect the angle of the bounce since it will pull it down. And that is what happens in the 'real' world as well.

If you want the angles to be exact after the bounce, you need to turn gravity off.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 27th Oct 2013 20:54
Just looping myself in to this as I want to learn more about AppGameKit physics. I the case we have here, wouldn't it make the most sense to have gravity off (as AL suggests) and just set friction?

Also, are you using your own sprite for the wall or the built-in physics walls? I'd try my own sprites or vice versa to see the results. Oh and I just found out that you have to change physics step to keep up with Sync as we discussed here:
http://forum.thegamecreators.com/?m=forum_view&t=208332&b=41

Not stepping correctly might affect the angular momentum behavior.

JRNTexas
13
Years of Service
User Offline
Joined: 24th May 2011
Location: Austin, Texas
Posted: 28th Oct 2013 06:32 Edited at: 28th Oct 2013 06:35
I set it to use rectangular shapes and there were no angles except when the ball touched right on the corner. So what I'm getting is not caused by a rectangular shape.

I turned off gravity and the problem is actually worse. With gravity on the puck would hit the wall, change direction (almost horizontal) but would eventually work it's way down the table, if left alone. With no gravity, the puck will hit the wall at an angle but will bounce off at a 90 degree angle and will travel horizontally forever, unless it is touched.

I used the built-in walls and then added my own. Same difference. I think I've tweaked just about every bit that can be tweaked and the results seem to be the same. The program was actually easy to write. I may start over and see what happens with only minimal code and sprites and go from there.

I also think I will shoot a video and make it available so you can see what I'm experiencing. I'm sure there is something that I've done to cause this but again, I'm pretty good at finding a workaround when I run into a problem. So I feel that I've changed every variable setting that would effect the results with no or worse results.

Both things are still true, there are only about 3 angles that are produced and when the puck contacts a player (both round). And when the puck hits a wall, instead of leaving at the angle (in reverse) that it entered at, it leaves the wall horizontally (literally) unless there is gravity or another force to compensate.

Video coming...And I will start from scratch to see if minimal number of elements give me the same results and work from there.

I really appreciate everyone's suggestions. It really gave me food for thought and in the worst case scenario, confirmed that I've tried not only what I can think of but I've also given other people's ideas a shot, with no positive results.

Must be a ghost in the code ;o)
JRNTexas
13
Years of Service
User Offline
Joined: 24th May 2011
Location: Austin, Texas
Posted: 28th Oct 2013 09:22 Edited at: 28th Oct 2013 09:55
OK.......

I got it down to minimum code. Actually 21 lines. Same problem.

Zip file with project folder, code & graphics attached....

Please download the file, unzip it, put it in your, "projects" folder, open it, and run it. See if you can modify the code to make it work correctly.

I've run this on Windows, Mac, Samsung Galaxy Pad, HTC Droid phone. All have same problem.

I know this must be something I'm doing wrong. Please tell me what I should be doing instead of what I am doing.

Thanks for everybody's help!!!!!!!!


Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th Oct 2013 10:11
Hi Jesse,

Here's how I would do it:


The problem is that when you set the position of a physics object every loop you loose the momentum etc for that sprite. Using a mouse joint the object is drawn to the position you set using forces so you keep momentum and the physics doesn't get screwed up.

It's an odd problem and I'm not 100% sure what causes the exact problem you are having but by keeping things moving using forces / joints rather than manually setting the potition it seems to eliminate the problem.

oct(31) = dec(25)
JRNTexas
13
Years of Service
User Offline
Joined: 24th May 2011
Location: Austin, Texas
Posted: 28th Oct 2013 10:30
Baxslash,

I just tried the code you posted and it exhibits the same issues.

The second angle is just as before ;o(

Try it on your system and see if you get the same results.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th Oct 2013 11:27 Edited at: 28th Oct 2013 11:39
I did try it and it seemed fine here... let me re-run it. Did you use the code I posted, I may have changed more than I thought?

EDIT: Try adding this line after you add your ball:


oct(31) = dec(25)
JRNTexas
13
Years of Service
User Offline
Joined: 24th May 2011
Location: Austin, Texas
Posted: 28th Oct 2013 20:41
Baxslash,

I'd really like to know if it runs the same on your system.

Here is the latest code I've run, including the new line I added that you suggested above. I used it on just the "puck" then I used it on both sprites.

I keep getting the same results. I have another Windows system that I may try to compile this on to see if it reacts like my development Windows system.

I will be shooting a video shortly. I will put it up on one of my websites and put a link to it here, so everyone can see how it runs and what I'm talking about.

I've included the code I'm currently running (still exhibiting the same problem), so that you can see if I put the new line of code in the right spot.

Thanks again for all the help!

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 28th Oct 2013 20:57
It's working ok for me, see video below.

The only change is the orientation to make it video friendly and a background to emphasise the angles. It worked just the same before these changes.



I can't see any problems with the code, the only thing I can think of is frame rate.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th Oct 2013 21:23
Mine works fine, same as Batvink's...

oct(31) = dec(25)
JRNTexas
13
Years of Service
User Offline
Joined: 24th May 2011
Location: Austin, Texas
Posted: 28th Oct 2013 21:57 Edited at: 28th Oct 2013 23:21
Batvink, Baxslash,

It looks good on your system.

Here is what it is doing on mine:

http://www.gameanvil.com/games/AGKVideo.html

One thing I did notice is the aspect ratio and orientation on your screen is different than mine. What is the code you are using to set up your screen, in main.agc and setup.agc?

Hey, and thanks again for your help.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th Oct 2013 22:01
That's very odd. That's the behaviour I got before I put the line in to remove friction. Are you restricting rotation? That might also cause something like this...

oct(31) = dec(25)
JRNTexas
13
Years of Service
User Offline
Joined: 24th May 2011
Location: Austin, Texas
Posted: 28th Oct 2013 22:39
I'm running the code exactly as you see it in the last code I submitted above.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th Oct 2013 22:58
Very strange. I don't get that weird bounce at all. Could you try deleting the physics walls and replacing them with physics sprites maybe?

Not sure if this has been asked but which version of AppGameKit are you running?

oct(31) = dec(25)
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 28th Oct 2013 23:16
Also it might be helpful if we can see what's going on with the PhysicsDebugOn and an FPS counter.
With my game I found that I had to skip physics steps to get stuff to update correctly in Android because of the unstable FPS

JRNTexas
13
Years of Service
User Offline
Joined: 24th May 2011
Location: Austin, Texas
Posted: 29th Oct 2013 00:16 Edited at: 29th Oct 2013 00:20
OK....

I think the problem has bee resolved with help from y'all.

I'm not sure how I made this happen, but originally, I started the project as "landscape" and copied some code from one of the examples.

I'm not sure what the culprit was/is.

When I started a new project as "generic", and pasted your code in, everything worked as it should, on my machine. !!!! But the funny thing is, when I started a new project in "landscape" first, and posted your code in, it worked the same way my original code worked.

However, after I started a new project in generic, and it worked and I then started a new project in landscape mode, it worked also.

I actually have no clue what the issue is/was.

So now I'm going to start over, with a code base that works, thanks to y'all.

It's getting expert help from the members on this site that makes this development environment great!

Oh, and that little piece of code:

SetPhysicsScale( 0.01 )
SetPhysicsGravity( 0, 0 )

Along with:

SetSpritePhysicsFriction ( 1, 0 )

Made a huge difference in how the game worked and how realistic the play was!

Thanks again, much appreciated!!!!!!!!
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 29th Oct 2013 08:14
The code worked ok for me in portrait and landscape. I created a generic project, and then I changed the width and height in setup.agc

I've just tried to change the setup.agc to landscape while keeping the virtual resolution portrait. It's still working okay for me.

All I can say is...weird! But at least you have it working now

JRNTexas
13
Years of Service
User Offline
Joined: 24th May 2011
Location: Austin, Texas
Posted: 29th Oct 2013 08:21
It is working fine now....
please take a look at my next post:


http://forum.thegamecreators.com/?m=forum_view&t=208467&b=41

I've encounter a new challenge (not in the system, just programming approach).

Login to post a reply

Server time is: 2024-11-24 21:30:37
Your offset time is: 2024-11-24 21:30:37