Making a circle of items shoot up.

Discussion in 'Plugin Development' started by JustinsCool15, Aug 13, 2014.

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

    JustinsCool15

    So I think this involves vectors and velocity. I'm not familiar with vectors too much and I want to learn, can someone point me to a good video tutorial or tell me what I should search. (I don't think reading the Java docs will help me with this one.)
     
  2. Offline

    fireblast709

    JustinsCool15 Entity#setVelocity(new Vector(0, speed upwards, 0)). Vectors are a direction with magnitude (length, power)
     
  3. Offline

    JustinsCool15

    fireblast709
    Thanks for the response. What do I need to search to learn more?

    fireblast709
    What I'm trying to do is make a circle (4 block radius) of books shoot up around the player about 8 blocks up and push any nearby entities about 10 blocks away. This seems kind of complicated to me. I really need to know how to do the circle thing though. I'm familiar with shooting items straight like a bullet, but not up or any particular direction.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  4. Offline

    fireblast709

    JustinsCool15 for circles, just use sin and cos.
    Code:
    int n = ...
    int radius = 4;
    double d = 2*Math.PI/n;
    double dx, dz;
    for(int i = 0; i < n; i++)
    {
        dx = Math.cos(d)*radius;
        dz = Math.sin(d)*radius;
     
        // Add dx and dz to your current Location and you get the Location of a specific Item.
        // Then set it's velocity to (0, y, 0) to make it fly up
        // It's probably wise to use a Runnable with the current y stored to check
        // whether they flew 8 blocks up. Then remove them. While they are flying, you can use those
        // ticks to push nearby mobs away (getNearbyEntities(x,y,z) is a good method for
        // getting those entities)
    }
     
    JustinsCool15 likes this.
  5. Offline

    JustinsCool15

    fireblast709
    Yeah I'm still super confused. I've tried researching sin and cod and making circles using them etc. I think it just confused me more.
     
  6. Offline

    fireblast709

    JustinsCool15 search for polar coordinates. The idea is that you base a 2D direction of one theta (angle in the range of 0 - 2pi), and multiply it by a radius.

    http://en.wikipedia.org/wiki/Polar_coordinate_system
    (Especially that picture next to conventions clearly shows that after you are at 360 degrees (which equals 2pi in radians), you will end up in the same position as with 0 degrees, closing the circle)
     
  7. Offline

    ChipDev

    How do you not know? Your picture states that you are morgan freeman.
     
  8. Offline

    bobacadodl

  9. Offline

    TheDummy

    fireblast709 JustinsCool15 This should iterate through a circle if I did it right:
    Code:java
    1. for( double theta = 0.0; theta < 2*PI; theta += fineTunedValue )
    2. {
    3. double blockX = sin( theta ) * radius;
    4. double blockY = cos( theta ) * radius;
    5.  
    6. // Do something with the coordinates (blockX, blockY)
    7. }
     
  10. Offline

    fireblast709

    TheDummy Ninja'd by more than a day (post #7)
     
Thread Status:
Not open for further replies.

Share This Page