[Homing Particle] How to get a direction from loc A to loc B?

  • 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 community!

    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.

Brocodo

Member
Feb 26, 2017
3
0
0
So I'm trying to create a "homing projectile" that follows the block a player is targeting and eventually explodes. The problem I'm facing is that I need a new direction for the code below. Right now it uses the direction the player is looking at, but I want the projectile to go where the player is aiming at (targeted block) from the location where it is at that moment ({_loc}). Does anyone have a clue how to do this? I can't find anything. Thanks!

Code:
set {_player} to player
        set {_loc} to location of player

        loop 300 times:
            set {_loc} to location 0.3 meter in direction of player from location of {_loc}
            show 1 cloud particle at {_loc} offset by 0, 0, 0 at speed 0.01

            #On collision with block
            if block at {_loc} isn't air or tall grass or fern or water:
                #Explode
                exit 2 sections

            wait 1 tick

P.S. How do I properly use the code tag on the new forums?
 
I don't know if I understand correctly what you need but i give i try
code_language.skript:
set {_distance} to "%distance between player and target entity%" parsed as number
loop {_distance} times:
    play cloud at location loop-number blocks forwards player to the player
    wait 2 ticks

You can use the drawLine expression too.
 
I don't know if I understand correctly what you need but i give i try
code_language.skript:
set {_distance} to "%distance between player and target entity%" parsed as number
loop {_distance} times:
    play cloud at location loop-number blocks forwards player to the player
    wait 2 ticks

You can use the drawLine expression too.

Mhm, not exactly what I mean but what does the
Code:
 x blocks forwards player to the player
do?

What I want to achieve is literally creating a "homing rocket laucher" mechanic that is found in many games. The particle/rocket will go to the location the player is looking at, and this may change at any moment.
 
That's the right thing that the code above do.
It will take the amount of distance blocks from player to target entity , and it will spawn the particles in every blocks in the right direction.
 
That's the right thing that the code above do.
It will take the amount of distance blocks from player to target entity , and it will spawn the particles in every blocks in the right direction.
Okay, I'm sorry now I checked the code it actually works, but I don't understand why haha
Could you explain me what the "forwards player" actually does? To me it seems that the distance in only set once, so the effect would not be able to go on forever. Basically it should be possible to let a particle fly forever if you keep the targeted location different.

What I got now is:

Code:
command /test2:
    executable by: player
    trigger:
        set {_distance} to "%distance between player and targeted block%" parsed as number
        loop {_distance} times:
            set {_loc} to location loop-number blocks forwards player
            show 1 cloud particle at {_loc} offset by 0, 0, 0 at speed 0.01
            wait 1 ticks
[doublepost=1494161965,1494161619][/doublepost]What I need is a way to create a direction, just like we can get the player's direction where he's looking at. Only this time I need it from the perspective of where the particle is, and not where the player is. So:

Instead of: direction from player to targeted block of player
I want: direction from <location> to targeted block of player

With any given location I want. This way I can move the projectile x blocks every tick in the direction of the targeted block.
 
lol I would help but I can't seem to find my particle projectiles skript anywhere *stuffs pp.sk into recycle bin*
 
"forwards player" just mean the direction he is looking at.
code_language.skript:
command /test2:
    executable by: player
    trigger:
        set {_distance} to "%distance between location of player and targeted block%" parsed as number
        loop {_distance} times:
            set {_loc} to location loop-number blocks forwards player
            show 1 cloud particle at {_loc} offset by 0, 0, 0 at speed 0.01
            wait 1 ticks
 
Status
Not open for further replies.