+ 2

Any ideas about how I could make this rotate when dragged around the circle?

I want to make it so you can click on the red circle and move it around the big black circle and I want the black line to rotate with the red circle, if you get what I mean. I can't figure out a way to determine how many degrees to rotate the parent based on cursor position though, any ideas? https://code.sololearn.com/Wk4U4j1uyOE2/?ref=app

3rd Jan 2021, 9:01 PM
Karak10
Karak10 - avatar
6 Respuestas
+ 4
Karak10 You can find in web the needed info about vectors. These examples help you to understanding the aplication of the theory in a code: https://code.sololearn.com/cbwAWWo1vUn4/?ref=app https://code.sololearn.com/W4teuZ25JqTM/?ref=app
4th Jan 2021, 9:52 AM
JaScript
JaScript - avatar
+ 3
I think Math.atan2() method is what I am looking for, I didn't have time to check it yet but I will try tomorrow. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2
3rd Jan 2021, 10:55 PM
Karak10
Karak10 - avatar
+ 1
JaScript I think I made it, it's not exactly the project I was trying to make, it is a test, but I will have no problem making the main project now that I know how to get the angle based on the mouse position, all I have to do is change the events and make it rotate whenever the red ball is dragged. https://code.sololearn.com/WA19A20A7A18/?ref=app
4th Jan 2021, 5:34 PM
Karak10
Karak10 - avatar
0
360 or 2pi. You can work with a vector.
3rd Jan 2021, 9:42 PM
JaScript
JaScript - avatar
0
JaScript I don't know how though Edit: nevermind, I did some research, I had learned to work with vectors in school in the past, I just didn't realize what vectors are because I'm not a native english speaker and in my language they are called different, I need to study them a little again to remember them since its been a while I have worked with them but I think I will find a way to make what I want.
3rd Jan 2021, 10:34 PM
Karak10
Karak10 - avatar
0
Your code is cool Karak10 . I tried it with a touchscreen and it works very well.
4th Jan 2021, 7:09 PM
JaScript
JaScript - avatar