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 / angle after physics collision

Author
Message
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 19th Mar 2013 13:56
it seems I am having difficulty bouncing a sprite around, I haven't coded in a bit though,losing interest when i always hit a brick wall!
but if I fire off a sprite(ball) at say 23 degrees then when it hits a vertical or horizontal block, the angle becomes straight up/down left/right, I can only gather that the balls new angle is calculated using the blocks current angle, I need to avoid this though and have a realistic bouncing angle! I am using setspritephysicsvelocity(ball,vx#,vy#) to move the ball under dynamic physics, the blocks are also physics enabled but just static

Hail to the king, baby!
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 19th Mar 2013 14:41
physics is a self running system, you put only a force or impulse in
and the rest should look right.

i think you overwrite the calculated velocity at collision with setspritephysicsvelocity
lilpissywilly
AGK Developer
14
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 19th Mar 2013 14:54 Edited at: 19th Mar 2013 14:55
Right.

First of all, if you use SetSpritePhysicsVelocity every loop you will actually set the direction of the ball yourself, so in effect you are not using the physics system as I think you want to.

If you want to do it that way you can, but you might as well not use box2d for that.

Using box 2d your would either SetSpritePhysicsVelocity or SetSpritePhysicsImpulse once to initiate your ball to move then let box2d move the ball in the right angle when it hits a surface.

By default gravity is on, you can change that with SetPhysicsGravity and/or SetPhysicsScale. Read help about those to learn more.

Your ball will behave in accordance to its set characteristics, which are at a default value to start with.
These include but are not limited to:

SetSpritePhysicsDamping - Set this to higher than nil if your want your ball to have an effect of moving against wind or travelling through water. Make it sluggish so to speak.

SetSpritePhysicsFriction - Does what it says on the tin. The friction set on the surface the ball hits also makes a difference.

SetSpritePhysicsRestitution - Sets the "bounciness" of your object. So if your ball is supposed to be bouncy play around with this setting. A setting of > 0.9999 will make your ball increase velocity after hitting a surface as opposed to slowing down.

I think those three are a good start.

If you need sample code of all this let me know.

My hovercraft is full of eels
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 19th Mar 2013 15:19 Edited at: 19th Mar 2013 15:29
Yeh i already set the gravity to zero of course else it would drop with gravity, i am trying to do a simple crazy golf game out of blocks and a ball, i have the angle sorted,i use damping to slow the ball down, friction and restitution is used, the latter on the bricks to make the ball bounce more!
.. setting the setspritephysicscanrotate() to 1 kinda helps but seems only good for one or 2 'bounces' then the problem of the angle straightening out reoccurs ?! I use damping and friction still coz i want the ball to slow down over time, the main firing of the ball is like this:





The speed# would of course be adjustable in reality but i fix it here for simple testing

Hail to the king, baby!
lilpissywilly
AGK Developer
14
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 19th Mar 2013 15:29 Edited at: 19th Mar 2013 15:31
What do you mean by angle? Are you setting it with SetSpritePhysicsVelocity every frame or are you letting box2d calculate the angles of a bounce?

Assuming you don't, and also assuming you mean SetSpritePhysicsRotate set to 0 since 1 is default, try setting friction of both ball and blocks to 1.0.

Edit: Ok saw your code now after you edited, answering my first question.

My hovercraft is full of eels
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 19th Mar 2013 15:38
yeh i am trying to let the box2d do the angles, setting the friction to 1 for both doesn't help, if i set the rotate to 1 then the problem is the same as setting it to 0, just not as obvious until the spin runs out! i have included the main project folder this time,as most of the code uses a file created with my level editor! use 'f' on the keyboard to shoot on a pc, change the angle with virtual joystick. thanks for any help!

Hail to the king, baby!

Attachments

Login to view attachments
lilpissywilly
AGK Developer
14
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 19th Mar 2013 15:43 Edited at: 19th Mar 2013 15:52
Are the bricks connected or do they have a tiny space between them?

Other than that, I can't see what the thing is that makes the ball turn to an even angle like that right now.

My hovercraft is full of eels
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 19th Mar 2013 15:55 Edited at: 19th Mar 2013 15:59
the bricks are connected, the image simply has a darker pixel border.
I ran into this problem with an arknoid clone i was doing also, it really spoils these ball games when the angle kinda straightens out on you, this should really only happen with severe counter spin! I think with the arknoid clone someone suggested slightly varying the angle of the bricks, but that would be abit 'one sided' so to speak!

Hail to the king, baby!
lilpissywilly
AGK Developer
14
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 19th Mar 2013 15:58
Have you tried changing scale? Maybe the size is considered too small to be precise? Grasping at straws..

My hovercraft is full of eels
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 19th Mar 2013 16:03
just tried...makes no odds changing scale or mass apparently.. nothing works with the commands available

Hail to the king, baby!
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 19th Mar 2013 17:57
i think SetSpritePhysicsRestitution(ball,0) means 0 bump.
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 22nd Mar 2013 11:51 Edited at: 22nd Mar 2013 11:53
ok after messing around with values, and a break from it to work on something simpler.... I found that messing around with different values of damping and friction has sorted it out, setting the friction of the ball to 0.01 i think and the damping of it to 0.5 equates to pretty good angular bounces,you absolutely must set the rotate to zero as the spin can change depending on what angle and speed it hits the brick, but also the main difference it had was when i added the setspritephysicsrestitution() to the bricks,setting it to a value of 1 seemed alot better than whatever default they had!
here is a video showing this!
thanks for the help, especially marcus who made me look into the setspritephysicsrestitution() command

Hail to the king, baby!
lilpissywilly
AGK Developer
14
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 22nd Mar 2013 13:11
Glad you sorted it out. Stopped looking down that route when you said you had messed with the three settings I suggested in post #3 of this thead.....

Quote: " i have the angle sorted,i use damping to slow the ball down, friction and restitution is used, the latter on the bricks to make the ball bounce more!"


My hovercraft is full of eels

Login to post a reply

Server time is: 2024-11-24 09:43:22
Your offset time is: 2024-11-24 09:43:22