#i have this unity 2d code that makes a

1 messages · Page 1 of 1 (latest)

barren echo
#

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

pure notch
#

you wanna bounce off imperfectly?

#

(lets say, within 5 degrees?)

charred heron
#

you are modifying the velocity

barren echo
#

yup

charred heron
#

make the velocity whatever you want it to be lol

pure notch
#

yeah, just rotate the direction vector a bit

barren echo
charred heron
#

then calculate the right direction

#

and put it in

pure notch
#

There's Random.Range to get a number, then there's Quaternion for the rotation or... Vector2.RotateSomething

charred heron
#

angle of incidence = angle of reflection

#

go do some geometry

#

and if it isn’t right, then you know your math is wrong

barren echo
#

okok i'll try change the rotation

charred heron
#

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

barren echo
#

idk the other guy said rotation

barren echo
charred heron
#

with math

barren echo
charred heron
#

get a pencil and paper, and start solving

charred heron
pure notch
#

(other guy said rotate the direction 😛 )

barren echo
charred heron
#

red ball hits blue surface, at the two green contacts

#

your code (even with correct math) will ignore one contact

pure notch
#

so, yeah... sadly such situations require some math knowledge and understanding 😅

barren echo
charred heron
#

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

barren echo
charred heron
#

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.