• Shooting Entity from Sky
    3 replies, posted
So.. I'd like to create a SWEP that shoots an entity from space (I'm going to use a melon). How do I achieve this? Basically, if I click with my marker on a location and a melon shoots down directly above it onto the point. Thanks. I'm fairly new to Lua.
Make a trace [B]self.Owner:GetEyeTrace().HitPos[/B], make another trace up util.TraceLine, and spawn the custom melon entity from that position ents.Create.
[QUOTE=Robotboy655;43010582]Make a trace [B]self.Owner:GetEyeTrace().HitPos[/B], make another trace up util.TraceLine, and spawn the custom melon entity from that position ents.Create.[/QUOTE] Thanks! Is there a way to shoot the melon from the sky straight down into the hit position?
If you want to simply give the melon velocity towards the hit position, melon:SetVelocity((melon:GetPos()-targetposition)*force) SetVelocity sets the directional vector relative to the entity's current position, so you don't want to just throw targetposition in there alone. By getting the difference between the two positions you have the relative direction the velocity needs to be. Test out some numbers for force (can be pretty high); a force of 1 would hardly push it at all. You might need to make it targetposition-melon:GetPos() instead of melon:GetPos()-targetposition; one of those will send the melon in the opposite direction. [editline]28th November 2013[/editline] Of course you could use a SetVelocity(Vector(0,0,-force)) to go straight down, but that would be very boring. Randomize the melon's spawning point to be at some angle above the target and then throw it as shown.
Sorry, you need to Log In to post a reply to this thread.