Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
oODemonologistOo wrote:This code doesn't really work properly at times, it gives me odd results and it's quite possibly because I failed to convert the angle right. How can I do it ?
Edit:
Spoiler: Dismiss this and instead see FDARI's post below
I think what you can do is provide the angle as [wiki=Definitions#Byte_angles]byte angle[/wiki] and then convert it to [wiki=Definitions#Fixed_point_angles]fixed-point angle[/wiki] to be used by [wiki]SetActorAngle[/wiki]:
TNT1 A 0 ACS_ExecuteAlways(998, 0, random(-36,36), angle)
Script 998 (int angle, int firstangle)
{
SetActorAngle(0, angle + firstangle);
}
This code doesn't really work properly at times, it gives me odd results and it's quite possibly because I failed to convert the angle right. How can I do it ? (First part is in decorate)
For reference, check out [wiki]Definitions[/wiki]. ACS functions either take BYTE angles (0-255), or fixed point angles (0.0-0.1).
(Byte angles: 360 degrees divides a circle in 360 parts, this divides a circle in 255 parts, but is otherwise similar.)
Decorate uses the same angles as the zdoom engine, but for decorate expressions and functions it converts to a number of degrees (0-360). In your code, the decorate expression "angle" returns a number within 360 degrees, rounded off to an integer for ACS. You need to convert this to a fixed point angle.
Spoiler: Extra descriptions if the wiki doesn't make it clear
x<<16: Convert to fixed point number. However, this will be in the range 0.0 - 360.0.
(x<<16)/360: This should put you in the range 0.0 - 1.0
360<<16 = 360.0
360.0 / 360 = 1.0
180<<16 = 180.0
180 / 360 = 0.5
Note: I divide fixed point integer by regular integer; that works ok.
Fixed/int: 360.0 / 360 = 1.0
Fixed/fixed: 360.0 / 360.0 = 1
They're both really ints, "the fixed point representation of a number = that number * 65536. ".
TNT1 A 0 ACS_ExecuteAlways(998, 0, ((frandom(-36,36) + angle) * 65536)/360)
// You'll be adding the angles together; can do that in decorate
// Passing the angle to ACS loses precision (only whole degrees can be sent); precision loss is reduced if we make the calculations before roundoff
// You probably don't need all that precision, but it might be nice to know.
// I used frandom, working with floats. That means the result can be a fraction of a degree. You may want to stick with regular random - I'm just putting it out there.
Script 998 (int fp_angle)
{
SetActorAngle(0, fp_angle);
}
insightguy wrote:
and how do you make "hitscan" projectiles without them firing the wrong way?
Huh? They fire in your back or something?
I've seen people complaining about them firing the wrong way. Can it just be like a normal projectile or do special things need to be added to every "bullet's" decorate
Maybe like a projectile that shoots hitscans? (In which case you have to make sure that the projectile is no longer targeting its own shooter before it itself starts shooting)
I guess you can use the angle and pitch parameters in [wiki]A_FireCustomMissile[/wiki] and [wiki]A_CustomMissile[/wiki] with frandom to randomize the spread. Angle and pitch are in degrees if I'm not mistaken.