Solved Move entity in a circle (Need math help)

Discussion in 'Plugin Development' started by Metal Julien, Jul 14, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Metal Julien

    Hi, I want to move an entity in a circle, where the midpoint a specific Location is. How can I do that?
    I want to teleport the entity every tick for that. But what's the formula?

    Code:
        Location entityloc;
            Location midpoint;
    double radius = midpoint.distance(entityloc);
            Bukkit.getScheduler().runTaskTimer(plugin, new Runnable(){
     
                @Override
                public void run() {
               
                   //Cockwise, start circle from entity loc around midpoint with radius radius
                }}, 1, 1);
     
  2. Offline

    bobacadodl

    Use the parametric equation of a circle
    x=cx+r*cos(a)
    y=cy+r*sin(a)

    r=radius
    cx,cy=origin
    a=angle from 0 to 2π radians or 0 to 360 degrees.

    just increment the angle :)
     
    chasechocolate and Metal Julien like this.
  3. Offline

    Metal Julien

    bobacadodl Buuuut, what's the angle on start? f.e. M(10,10,10) E(12,10,9)
    E is the Entities loc, M is the midpoint. What's the angle here?
     
  4. Offline

    bobacadodl

    Math.atan2(y-cy, x-cx) = angle


    so in your case M(10,10,10) E(12,10,9)
    You dont need the Y coord since your plane is X and Z

    Math.atan2(12-10,9-10); = angle in radians

    i think....

    Havent done trig in a while :p
     
    Metal Julien likes this.
  5. Offline

    iFamasssxD

    :confused: Wert? Seems like it would cause tons of lag.
     
  6. Offline

    bobacadodl

    Yeah, it could... :/ There's no better way AFAIK to do what he wants though.

    Hopefully, there arent too many of these mobs moving in circles at once.
     
Thread Status:
Not open for further replies.

Share This Page