1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Pulling player rather than pushing.

Discussion in 'Development' started by Sushant, Mar 19, 2022.

  1. Sushant

    Sushant Creeper

    Messages:
    5
    GitHub:
    NightSling
    Is it possible to create a command that can pull all the players in the radius? I've already done up to the getting player in the radius part. I'm just wondering how I shall be pulling players. Can someone help me with that? I tried doing vector multiplication by -1 and subtracting the target location but it didn't go as expected.
     
  2. bruno99

    bruno99 Spider

    Messages:
    12
    GitHub:
    udachin26
    Hey! Of course you can. Interesting to see.
     
  3. Sushant

    Sushant Creeper

    Messages:
    5
    GitHub:
    NightSling
    Do you have idea on how I shall do that? I'm really looking forward to it!
     
  4. bruno99

    bruno99 Spider

    Messages:
    12
    GitHub:
    udachin26
    How about this logic. Check whether the other player keeps the distance to the radius ratio. If the distance is observed with the number of the radius, then we attract to the player
     
  5. Primus

    Primus Zombie Pigman

    Messages:
    749
    Get the vector that points to the center of the circle, apply that vector.

    dir = v1.sub(center).normalize().mult(-1)
    player.applyForce(dir)
     
  6. bruno99

    bruno99 Spider

    Messages:
    12
    GitHub:
    udachin26
    How about using the distance function in Vector3?
     
  7. Primus

    Primus Zombie Pigman

    Messages:
    749
    Yes, that is how you would filter out players to get ones inside the circle. My answer was more aimed towards actual action to attract players to the center.

    PHP:
    affectedRadius 20;
    center = new Vector3(xyz);
    subjects array_filter(level.getPlayers(), fn(Player p): bool => p.distance(center) <= affectedRadius)

    for(
    subject in subjects) {
        
    dir v1.sub(center).normalize().mult(-1)
        
    player.applyForce(dir)
    }
    There is nothing to copy and paste, to avoid spoon-feeding and encourage learning.
     
  8. Sushant

    Sushant Creeper

    Messages:
    5
    GitHub:
    NightSling
    Yeah, indeed I'll test it in a bit and let all know
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.