[code question] spawining along a line

Discuss all aspects of editing for ZDoom.
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

[code question] spawining along a line

Postby zrrion the insect » Tue Oct 03, 2017 10:21 am

I am attempting to get every instance of BFGextra to spawn a line of actors between itself and the BFGball that spawned them, preferably a jagged line. I have been attempting to look this up but have thus far only found example code that included built in methods for doing some of the math (methods that zscript doesn't have)
Any help on this would be appreciated, even just pointing me towards a good tutorial/good example code would go a long way.
User avatar
zrrion the insect
Like a fish in a child's hands.
 
Joined: 25 Jun 2009
Location: Time Station 1: Moon of Glendale

Re: [code question] spawining along a line

Postby kodi » Tue Oct 03, 2017 10:37 am

Off the top of my head this ought to work with minor adjustments.
Code: Select allExpand view
double ang = GetAngle(0,AAPTR_TARGET);
double range2d = GetDistance(0, AAPTR_TARGET);
double range3d = GetDistance(1, AAPTR_TARGET);
double pit = atan2(range2d, self.z - target.z) //may need to reverse the z comparison, I forget the right order easily
double sparsity = 10.0;

for(int i = +; i <=  range3d/sparsity, i++)
{
//use these for spawn function arguments instead and maybe add some randomization. The proper method would be real bezier curves but I can't into math that well.
x = cos(ang) * cos(pit)*(sparsity*i);
x = sin(ang) * cos(pit)*(sparsity*i);
z = sin(pit) * (sparsity*i);
}


I think maybe a native railgun function could do the trick just as well, with custom spawnclass and a range limit of GetDistance(1, AAPTR_TARGET)
User avatar
kodi
Proscrastinator
 
 
 
Joined: 06 May 2013


Return to Editing (Archive)

Who is online

Users browsing this forum: Ahrefs [Bot] and 3 guests