last day (15 days later) » 

8:39 PM
Okay, so I guess I didn't fully explained the problem last time
 
I got that feeling
 
I'm remaking a breakout game that I was working on a few months ago.
 
Okay.
Breakout has linear ball movement, not circular, or are you doing something special?
 
Basically what I want to do is make the ball curve if, when it collides with the paddle, both are going in opposite directions
I also want the curve to be proportional to the speed of the paddle on the moment of collision.
 
Okay
 
8:43 PM
I mean the radius of the circumference on which the ball will travel
 
You could use the circle radius from the previous examples to control how the ball curves, larger radius when you want less altering
 
you talked about the ball spinning around the origin
but that would change depending on where the collision ocurred
 
yeah, that's what you need to solve in this case
let me think
 
also, I don't want it to curve so that it falls back down again
so I'm guessing the origin ypos should be larger than the screen max height
 
well, you know the point where the ball hit the paddle, you can calculate the next position it needs to have after the collision (reflecting from the paddle), and you can use that and 90 degree angle to get the origin of which the ball circles around
yes, it should be
 
8:49 PM
I don't understand. Why a 90 degree angle?
 
you can use pythagoras theorem if it's 90 degrees
I'm typing, a sec
origin = sqrt(ballPositionAfterHit^2 + hitPointOnPaddleInWorldCoordinates^2)
something like that
that might or might not work, I'm not sure
lol thats just silly, a sec I'll think it thru better :D
 
haha, ok
 
okay
let's say point A is where the ball hit the paddle, and point B is the new position of the ball after the hit according how it reflected (like it normally would without rotation)
 
wait!
I gotta go take a shower, can you wait?
 
yeah, I'll just write it here meanwhile
it's not hard
 
8:59 PM
k, brb
 
subtract A from B, then you get C, and if you flip the components (x = y, y = x) and normalize you will get the normal for that vector from A to B. Now you can use that normal to set where you want the origin of the circle to be by multiplying it with some scalar value that determines how much curve you want for the ball
that can be got for example like 1 / paddleMoveDelta
 
Pip
ahh the Pythagorean theorem
a^2 + b^2 = c^2
or
sqrt(a^2 + b^2) = c
 
and in case you don't know, paddleMoveDelta = paddleCurrentPos - paddleLastPos
yes that is pythagorean
it could be used here too, but this is just simpler
 
Pip
lol
 
the result is the same
also, when the ball hits something else you might want to reset the motion to be linear, or just put the origin of the circle really far away
like, really really far away
derp "linear"
I have no idea what's the english term for something travelling straight line instead of something else
"straight path" might be better
oh, wait, the normal is x => -y, y => x
you need to add the sign there
 
9:26 PM
I'm back
so C would be a vector of length distance_travelled right?
 
yeah, it's just vector from point A to point B
 
I want to go over this step by step until I understand the logic
but I'll try not to bore you.
So, why flip the components?
 
that makes it a normal for that vector
 
yeah, I visualized it now
it exactly flips the vector
 
yep
 
9:30 PM
by normalize you mean to set its length to one?
 
yes
 
k
The paddle last pos would be the one before the collision or the one on the collision?
 
no you need to know the ball position where it hit the paddle
in world coordinates
 
31 mins ago, by Lasse
and in case you don't know, paddleMoveDelta = paddleCurrentPos - paddleLastPos
that's what I'm asking about
 
oh, that
it's the last frame's position
so I guess it's the position right before the hit
 
9:35 PM
ok
I don't need to keep track of it, right? I can just calculate it back
 
it's easier to keep track of it, but you can calculate it too if you want
 
ok
so let me see if I got this
the bigger is paddleMoveDelta, the larger will be the curve
I mean
the radius
 
no, the opposite, because you do 1/delta
yes
 
yeah, that was exactly what I was going to ask you
 
uh, wait, no
 
9:38 PM
I wanted the reverse
 
:D
let's say delta is 10
1/10 = 0.1, the radius will be then 0.1 (for example, in reality you multiply that with the value you want)
if the delta is 20, and the paddle moves faster
it's 1/20 = 0.05
so it's closer
so yeah, the bigger delta, the smaller the radius, and more curve will be apparant
 
okay, so to sum this up
I get the vector between A (lastBallPos) and B(nextBallPos), flip that, normalize it then multiply by something like 1/paddleMoveDelta * scalar
and that's the origin
 
yep
 
that was beautiful
k, could you tell me again those circular movement equations
I couldn't find them in the transcript for some reason
 
they got deleted by raging SE employee
newx = sin(travelAmount) * radius;
newy = cos(travelAmount) * radius;
the travelAmount starts from zero, and should cumulate
 
9:45 PM
travelAmount being just the linear distance?
 
yeah
the distance from the starting point
 
what do you mean 'starts from zero'? why?
you mean the distance since it started spinning?
 
you need to tweak that a bit though, larger radius will move the ball more with the same values
yes
also you need to find out the starting point on the circle
 
why should it cumulate?
 
I meant, if the ball travels like 1 unit per frame, you need to cumulate those, so it'll be 3 units after 3 frames
 
9:48 PM
okay, its getting weird now
 
it's like the deltatime needs to be added to the totalTime
 
shoudn't the travelledAmount be the distance from lastpos to currentpos?
 
the original example was this:
totalTime += deltaTime;
newx = sin(totalTime);
newy = cos(totalTime);
no, it should be from where the ball got hit by the paddle
 
Damn, everytime I try to understand this I get confused
 
Pip
alright
I can explain this part
 
9:52 PM
please try
 
Pip
@Jovito travelledAmount should start over every time it collides
with the paddle
so, make a lastCollidePos
and the travelledAmount will be the distance between the currentPos and the lastCollidePos
done
 
the thing is
if you tell me "just do this and it will work" I can go back, code it over and everything will be cabbagewonderful
what I don't understand is why
 
to understand you need to know how sin and cos works
In mathematics, the sine function is a trigonometric function of an angle. The sine of an angle is defined in the context of a right triangle: for the specified angle, it is the ratio of the length of the side that is opposite that angle to (divided by) the length of the longest side of the triangle (i.e. the hypotenuse). Trigonometric functions are commonly defined as ratios of two sides of a right triangle containing the angle, and can equivalently be defined as the lengths of various line segments from a unit circle. More modern definitions express them as infinite series or as sol...
"Relation to the unit circle"
sin() and cos() will always return a value from -1 to 1
 
okay, you think I should study some trig before attempting this?
 
If you want to fully understand it, yes
 
10:01 PM
well, where's the fun in asking you for the answer to my problem and just hardcoding it?
at least I think I understood most of it
anyway, thanks for you help @Lasse, I'll try this again when I have learnt enough to understand it.
is that right? learnt?
 
learnt is british english
and no problem, I'm glad to be helpful :)
 
10:27 PM
@Lasse can this talk be deleted too? I'd like to come back to it in the future
 
no, the last discussion was deleted because of the others had the discussion of which the SE employee didn't like at all
he just deleted every message in between a timespan
three people got actually banned for that too
 
.-.
 
for 8 hours
so, it was just collatetral damage
 

last day (15 days later) »