Solved Shoot projectile towards an entity

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

PatoFrango

Active Member
Jul 12, 2017
240
14
18
Hi,

This is one of those simple things that can be easily done but your brain just makes it harder. How would I shoot a projectile from a location towards a player?

I've tried

code_language.skript:
shoot a snowball from location at 919977, 128, 978119 in world "water" at speed 1 in direction of loop-player

but it shoots the projectile from the coordinates towards the direction the player is facing, not to where he's at.
 
Instead of "in direction of loop-player" try "towards loop-player"
"Direction of loop-player" is an expression that represents the direction loop-player is facing.
 
Instead of "in direction of loop-player" try "towards loop-player"
"Direction of loop-player" is an expression that represents the direction loop-player is facing.
I've already tried that, it tells me that "loop-player" is not a direction
 
You can do "direction from %location% to %location%" to get a direction pointing from one spot to another, so it should be something like this:
code_language.skript:
set {_loc} to location(919977, 128, 978119, world("water"))
shoot a snowball from {_loc} at speed 1 in direction from {_loc} to loop-player
 
You can do "direction from %location% to %location%" to get a direction pointing from one spot to another, so it should be something like this:
code_language.skript:
set {_loc} to location(919977, 128, 978119, world("water"))
shoot a snowball from {_loc} at speed 1 in direction from {_loc} to loop-player
Thanks very much, I'm going to try that, but in the meantime I've crossed an even more efficient solution: applying the pythagorean theorem in the program.

code_language.skript:
every 6 seconds in "water":
    {challenge9.onGoing} == true
    loop all players in "water":
        "%region at loop-player%" contains "challenge9"
        set {challenge9.Tile} to "%region at loop-player%"
        if {challenge9.Head} == "red":
            set {_x} to floor(loop-player's x-coordinate - 919977) / 10
            set {_z} to floor(loop-player's z-coordinate - 978119) / 10
            set {_y} to floor(loop-player's y-coordinate - 128) / 10
            if {_x} is 1 or -1:
                set {_x} to "%{_x}%.0"
            if {_z} is 1 or -1:
                set {_z} to "%{_z}%.0"
            console command "/execute %loop-player% ~ ~ ~ /summon fireball 919977 128 978119 {damage:0,direction:[%{_x}%,%{_y}%,%{_z}%],ExplosionPower:0}"

First, I calculated the difference between the player's and the shooting location's x-coordinate (which is 919977), then I rounded the result down so that I get the block's exact coordinate, not for example 7.9 which would mean that the player is at the edge of the block. With this we've got 7, but if I put that number in the command it would just be too big and inaccurate PLUS the command's syntax actually requires a decimal part, so I divided it by 10 and I got 0.7, which was just what I wanted. Did the same thing with z and y. The problem is, sometimes the result would actually be just 1 instead of 1.0, because Skript simplifies it to 1, so I had to create two conditions, one for x and other for z which tells if the result of one of them is 1 or -1, it converts the value into a string adding the .0 in the end. Then, the ACTUAL command executes the theorem to calculate the direction with the given values between de x and the z and does some crazy 3D magic with the y. The only thing I know for y is that it works xD, not sure how, but basically the command then converts the result into some kind of vector and ta-daa, there it is, the automatic projectile-direction-calculator-3000
 
This is exactly what the Skript code will be doing internally on some level, I doubt it's much more efficient to do it yourself.
 
This is exactly what the Skript code will be doing internally on some level, I doubt it's much more efficient to do it yourself.
Yeah, maybe you're right. Still, it was pretty fun to figure out. It forced my brain to think, which is what I always aim for when I'm coding.
Thanks!
[doublepost=1530821919,1530808998][/doublepost]
You can do "direction from %location% to %location%" to get a direction pointing from one spot to another, so it should be something like this:
code_language.skript:
set {_loc} to location(919977, 128, 978119, world("water"))
shoot a snowball from {_loc} at speed 1 in direction from {_loc} to loop-player
Actually it doesn't work RIP
It says "Could not understand this condition/effect: shoot a..."
 
Just an issue with the syntax then. Probably need to remove the "in" before the direction
 
Just an issue with the syntax then. Probably need to remove the "in" before the direction
Ah, it works now, and how would I summon a fireball that doesn't destroy blocks?

EDIT: Nevermind, that's not what I meant, I meant to ask how would I make so the fireball doesn't instantly explode when it's spawned? Because that's what happens.
 
Last edited:
Ah, it works now, and how would I summon a fireball that doesn't destroy blocks?

EDIT: Nevermind, that's not what I meant, I meant to ask how would I make so the fireball doesn't instantly explode when it's spawned? Because that's what happens.
If you spawn it at an entity you have to spawn it a little bit in front of that entity
 
Status
Not open for further replies.