I’m trying to make a SENT home in on the location of the player, and then despawn before it hits them
It’s the last step in the “Saber Throw” Force power, I’m adding to my custom redesign of the existing Lightsaber SWEPS.
I already have all other parts of it working except for this.
Basically I currently have the SWEP set to do this.
Spawn a SENT that is a spinning model of a lightsaber that is thrown in the aimed direction of the player.
When it hits a wall or prop, it embeds itself into it, with a scorch mark, and some sparks, and a cutting sound effect. After awhile this embedded saber fades.
When it Phys Impacts a NPC, or Player it is set to fire a AR2AltFire bullet at the hit target, this triggers the AR2 De-solve effect, keeping it consistent with what happens when a player is killed by the normal melee attack. It then despawns, thus cleaning up the area of un-needed entities.
Everything above is done, and works.
What I want to add is this:
After an NPC or Player is hit and before the original thrown Lightsaber entity despawns, I want it to spawn another duplicate entity of itself that will then fly back to the attacking player, homing in on them if they have moved since they threw the saber, and then despawn right before it hits them, to give the illusion of them catching it.
Another issue is getting the player to “drop” their SWEP(without actually leaving it at their feet) when the saber is thrown, and “re-equip” it when it is caught again. But that is not even a concern if I can’t get it to return in the first place.
I have considered using the same code that drives the original throwing on the main saber entity from the SWEP, but it’s direction is determined by this code:
phys:ApplyForceCenter(self.Owner:GetAimVector() * 50000)
if I put that in the Think function of the second entity it would change it’s direction every tick, thus homing in, the issue is how do I obtain a vector BACK to the player, and update this vector as the player moves.
Any help is appreciated!