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

How to let arrow go straigt

Discussion in 'Development' started by Mohagames205, May 5, 2019.

  1. Mohagames205

    Mohagames205 Spider Jockey

    Messages:
    26
    GitHub:
    mohagames205
    Hi everyone

    I am trying to make a plugin and in this plugin you can shoot arrows from a stick. Now I want the stick to shoot the arrow straight, but this does not happen. I tried increasing $baseforce but that doesn't change anything.
    This is my code:

    PHP:
    public function onInteract(PlayerInteractEvent $e){
            
    $player $e->getPlayer();
            if(
    $e->getItem()->getId() == ItemIds::STICK){
                
    $nbt Entity::CreateBaseNBT(
                    
    $player->add(0$player->getEyeHeight() + 10),
                    
    $player->getDirectionVector(),
                    (
    $player->yaw 180 360 0) - $player->yaw,
                    -
    $player->pitch
                
    );
                        
    $diff $player->getItemUseDuration();
                        
    $p $diff 20;
                        
    $baseForce min((($p ** 2) + $p 2) / 31);
                        
    $entity Entity::createEntity("Arrow"$player->getLevel(), $nbt$playertrue);
                        
    $ev = new EntityShootBowEvent($player, new Bow$entity50);
                        
    $ev->call();
          }
       }
    I hope someone can help!
     
  2. Primus

    Primus Zombie Pigman

    Messages:
    749
    Remove gravity equation from Arrow class?

    Arrow::$gravity = 0.5; (Link)

    Extend current Arrow class and modify that value. Just first idea that popped into my mind. Haven't been active nor following along the code changes.
     
    Last edited: May 5, 2019
  3. Mohagames205

    Mohagames205 Spider Jockey

    Messages:
    26
    GitHub:
    mohagames205
    Like this?
    PHP:
    public function onInteract(PlayerInteractEvent $e){
            
    $player $e->getPlayer();
            if(
    $e->getItem()->getId() == ItemIds::STICK){
                
    $nbt Entity::CreateBaseNBT(
                    
    $player->add(0$player->getEyeHeight() + 10),
                    
    $player->getDirectionVector(),
                    (
    $player->yaw 180 360 0) - $player->yaw,
                    -
    $player->pitch
                
    );
                        
    $entity Entity::createEntity("Arrow"$player->getLevel(), $nbt$playertrue);
                        
    $ev = new EntityShootBowEvent($player, new Bow$entity50);
                        
    $ev->call();
          }
       }
     
  4. Mohagames205

    Mohagames205 Spider Jockey

    Messages:
    26
    GitHub:
    mohagames205
    How
    How would I extend to 2 classes? Because I already extend to PluginBase
     
  5. Primus

    Primus Zombie Pigman

    Messages:
    749
    Create new class.

    Take a look at source code and find where the gravity is applied.
     
  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.