Sprite velocity not changing when interacting with other sprites

A student in my class wants their character sprite to decrease or increase velocity depending on the item they collect. We already have a a set a constant “gravity” for the character sprite, but we can’t quite get it to change permanently when they “collect” an item. Below is the game so far.

Hello @jyorke,

In your code, you are successfully checking for the collision between the character and the rings, and when it touches, that line of code to change the velocity, DOES kick in, but only briefly because the else statement is executing much more frequently than the main statement and the else statement automatically resets the velocity to 2. So for most of the fall, the velocity will be 2. If it ever becomes 6, it is almost immediately restored to 2 because the character isn’t touching the ring very long. You may want to separate those statements or eliminate the else clause and find a different way to trigger it … OR you could not set the velocity to be an absolute value if the else clause is activated …

Hope this helps!

Mike

Thanks a ton! You got me to think about it slightly differently. We ended up removing those else statements, and created a variable for gravity, and adjusted our velocity counters to incorporate it.

Here is how it works now…

1 Like