Do you want it to just jump up and down as if there's no friction i.e. it bounces up and down at the same height throughout? If so, then based on the level of the table it's bouncing off, set the y velocity to negate whenever it the bottom level's y value, and when it hits 'near' where you want it to start going down, the y velocity continues to go down until it's negative of what it was going up
Bit complicated to write, read it a few times if you must
Do you want it to just jump up and down as if there's no friction i.e. it bounces up and down at the same height throughout? If so, then based on the level of the table it's bouncing off, set the y velocity to negate whenever it the bottom level's y value, and when it hits 'near' where you want it to start going down, the y velocity continues to go down until it's negative of what it was going up
Bit complicated to write, read it a few times if you must
so in simpler terms are you saying that when it hits the bottom of where you want it, make it go up, and when you hit the top, make it go down?
so in simpler terms are you saying that when it hits the bottom of where you want it, make it go up, and when you hit the top, make it go down?
how would i do something like this?
Not quite, because when it bounces at the bottom it goes straight back up doesn't it? But when it goes up it doesn't suddenly go down at the same angle, it slowly stops going up and starts going down.
What you want to do is (note that I'm considering the ball center is the normal ball center):
Code:
//When the ball is touching the bottom of the ground, y velocity inverses
if(image.center.y - ballRadius == ground.y) {
ballVelocity.y = -ballVelocity.y;
}
//When ball is more 50 pixels off the ground, it starts to slow down and go down
if(image.center.y - ballRadius - 50 > ground.y) {
ballVelocity.y = ballVelocity.y - (image.center.y - ballRadius - 50 - ground.y)
}
What I've done in the second part is make the ballVelocity.y go down by the amount of difference between its current height and 50 pixels above the ground. This should work however I'm not sure how quick it updates so it might keep updating so quickly that it immediately goes down. You're gonna have to check this
Not quite, because when it bounces at the bottom it goes straight back up doesn't it? But when it goes up it doesn't suddenly go down at the same angle, it slowly stops going up and starts going down.
What you want to do is (note that I'm considering the ball center is the normal ball center):
Code:
//When the ball is touching the bottom of the ground, y velocity inverses
if(image.center.y - ballRadius == ground.y) {
ballVelocity.y = -ballVelocity.y;
}
//When ball is more 50 pixels off the ground, it starts to slow down and go down
if(image.center.y - ballRadius - 50 > ground.y) {
ballVelocity.y = ballVelocity.y - (image.center.y - ballRadius - 50 - ground.y)
}
What I've done in the second part is make the ballVelocity.y go down by the amount of difference between its current height and 50 pixels above the ground. This should work however I'm not sure how quick it updates so it might keep updating so quickly that it immediately goes down. You're gonna have to check this
i could make a new timer, how fast of a timer would work well with this?
i could make a new timer, how fast of a timer would work well with this?
I don't have a clue, test yourself You don't really need to ask that question do you? Just put in a value and see how it works. Best to start with a slow timer so that it's obvious whether it's working, then bring the time down as you see necessary.
UIView animates everything at the same time, that code would make nothing happen since they cancel eachother out
Haha, good point. Guess I'm just a little off my game today. But you could put the reverse into the animationdidfinish method if that's what you wanted.
He doesn't want to go forwards and then back to its original place, he wants it to hop, so constantly go forward, so the image.center.y value (seeing as it seems hes working in LandscapeLeft so y value is horizontal) should stay as -10 in the second animation too, and only image.center.x go to +10. However that would make it only move in diagonals whereas slowly changing the x value will make it look more like a hop.
I just realised you're still trying to do it through UIView animations. I think for the transition stage you need to have set where there is some sort of ballVelocity.y set so that you can make it look more realistic by going up then slowing down and coming back down again.
He doesn't want to go forwards and then back to its original place, he wants it to hop, so constantly go forward, so the image.center.y value (seeing as it seems hes working in LandscapeLeft so y value is horizontal) should stay as -10 in the second animation too, and only image.center.x go to +10. However that would make it only move in diagonals whereas slowly changing the x value will make it look more like a hop.
I just realised you're still trying to do it through UIView animations. I think for the transition stage you need to have set where there is some sort of ballVelocity.y set so that you can make it look more realistic by going up then slowing down and coming back down again.