Pregunta

I am developing a little videogame using JAVA in which I have to do a circular movement to create a smooth transition of an object but I can't figure it out how to apply the circumference equation to make this.

Here is an image of what I am trying to do:

enter image description here

The character of the top has to move to the bottom with this circular movement. I know the center of the circumference and the radius but I dont know how to extract an equaction to move this character that also takes into account a given speed.

Any tips please? Thank you very much!!

¿Fue útil?

Solución

The arclength (distance around a circle) is given by s = rϑ. Since you want to do this based on a speed, you can take the derivative (basically, divide by t on both sides): v = rϑ/t, or ϑ = vt/r. Internally, you'll store the values of r,v, and t and use the concept of the unit circle to get the actual x and y values:

x = r * cos(ϑ) = r * cos(vt/r)
y = r * sin(ϑ) = r * sin(vt/r)

while you increment t on every draw cycle. You'll of course have to translate (x,y) based on the center of the circle.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top