#i have this unity 2d code that makes a
1 messages · Page 1 of 1 (latest)
for example, this is how it would normally work,
then this second example, my range variable is set to 45, and when it bounces, it bounces off randomly within the range
you are modifying the velocity
yup
make the velocity whatever you want it to be lol
yeah, just rotate the direction vector a bit
yeah but if i do that it might go off in the same direction
There's Random.Range to get a number, then there's Quaternion for the rotation or... Vector2.RotateSomething
angle of incidence = angle of reflection
go do some geometry
and if it isn’t right, then you know your math is wrong
okok i'll try change the rotation
also, make sure your rigidbody is in continuous collision mode, or nothing will make sense
what rotation
calculate the direction
btw, a Collision2D can have multiple contacts
idk the other guy said rotation
how would i do that
with math
does that mean my code is prone to error?
get a pencil and paper, and start solving
big time, yes
(other guy said rotate the direction 😛 )
i have no idea on where i should start T_T
red ball hits blue surface, at the two green contacts
your code (even with correct math) will ignore one contact
so, yeah... sadly such situations require some math knowledge and understanding 😅
what type of math knowledge though so i can search it up?
If you plan to do work coding physics, you need to know basic math and physics. If this relatively simple case is not something you can handle on your own, you should probably not be making any physics based code
you need to know basic geometry, trigonometry, and vector math at the very least
if you don’t understand vectors, anything with vectors is going to make your life extremely challenging
in theory, you should have learned everything you really need in high school already
ok thank you
yeah im still in 10th grade still haha
well, pay attention in school. We had a middle aged guy here a couple months ago who wanted to make a football game. He skipped/slept through math. He could not do the simple algebra to calculate where the damn ball should go. That project died.