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 to Increase Sprite Velocity?

Author
Message
Splock
12
Years of Service
User Offline
Joined: 3rd Oct 2011
Location:
Posted: 3rd Oct 2011 09:13
Hi all,

Newbie here so bear with me Coding in Tier 1.

Does anyone know how to increase the velocity of a sprite by the amount of force from another sprite? Basically I have a paddle (1st sprite) controlled by the player via the mouse that hits a ball (2nd sprite). I want the ball to move faster based on how hard the paddle hits it, so the faster the player moves the mouse the faster the ball will move once contact is made. I have this done to the point where the ball will bounce off the paddle but I can only get it to move by the same amount each time, it doesn't matter how "hard" it gets hit.

I'm using damping to slow it down after it's hit and I have mass values set as well as restitution for both sprites. I've tried SetSpritePhysicsVelocity as well as SetSpritePhysicsForce but I can only get the velocity command to move the ball. Otherwise I just push it around with the paddle.

Any advice at all would be greatly appreciated!

Thanks!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd Oct 2011 19:14
Quote: "I'm using damping to slow it down after it's hit"

This could be your problem. Since you're using physics sprites anyway you don't need to calculate this kind of stuff. Turn the damping off or right down to nothing and you should see a huge improvement.

Just add forces to the paddle or control its position and angle and let the ball get hit by it, it should react as expected.

That would be my advice

JHA
20
Years of Service
User Offline
Joined: 30th Dec 2003
Location: Massachusetts, USA
Posted: 4th Oct 2011 00:02 Edited at: 4th Oct 2011 00:03
Pretty sure you do NOT want to use SetSpritePhysicsVelocity, as this sets the velocity at a specific rate and will not work correctly with Forces or Impulses.

Here is the description in the help for it:



Wish I could help more, but I am still trying to get my head wrapped around the physics commands too.

Thanks,
JHA
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 4th Oct 2011 00:28
You can use the "SetSpritePhysicsVelocity" command as a 'one off' to get something moving and it will still react properly, just don't call it every loop!

Smashton
12
Years of Service
User Offline
Joined: 29th Sep 2011
Location:
Posted: 4th Oct 2011 03:19
He wants something like this effect:

http://www.emanueleferonato.com/2008/11/20/dragging-objects-with-box2d-flash/

Try to use:
CreateMouseJoint( iJointIndex, iSpriteIndex, x, y, maxForce )

This might work for you
Splock
12
Years of Service
User Offline
Joined: 3rd Oct 2011
Location:
Posted: 4th Oct 2011 07:27
Thanks everyone! Now it works for the most part except for two problems:

Using CreateMouseJoint and setting SetJointMouseTarget to GetPointerX and GetPointerY allows the sprite to follow the mouse without using SetSpritePosition fixed my physics problems, but the sprite lags behind the mouse pointer a bit. Is there anyway to make the sprite follow the mouse pointer 1:1?

And the other problem is that the velocity seems capped somehow. The harder the paddle impacts the ball the more velocity it gets but the paddle and ball cap at 600 units, which I see when I Print the values of GetSpritePhysicsVelocityX and Y for both sprites. Basically you can fling the mouse pointer across the screen but you aren't going to go faster than 600 units, no matter how fast you move it. Move the mouse slower though and you get the right velocity up to that 600 max. I'm guessing I am using SetSpritePhysicsForce incorrectly but I am still playing with it
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 4th Oct 2011 11:06
"CreateMouseJoint(iJointIndex, iSpriteIndex, x, y, maxForce)"
What about playing with the "maxForce" value?

Login to post a reply

Server time is: 2024-04-23 22:32:57
Your offset time is: 2024-04-23 22:32:57