Skip to content

Commit

Permalink
Set the script origin local angles and angles when setting the angle
Browse files Browse the repository at this point in the history
This fixes the issue where a ScriptOrigin would rotate in the wrong direction
  • Loading branch information
smallmodel authored Oct 21, 2024
1 parent 64696c7 commit 8ecbe1d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
56 changes: 55 additions & 1 deletion code/fgame/scriptslave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2104,9 +2104,39 @@ Used as an alternate origin for objects. Bind the object to the script_origin
in order to simulate changing that object's origin.
******************************************************************************/

// Added in 2.30
Event EV_ScriptOrigin_SetAngle
(
"angle",
EV_DEFAULT,
"f",
"newAngle",
"set the angles of the entity using just one value.\n"
"Sets the yaw of the entity or an up and down\n"
"direction if newAngle is [0-359] or -1 or -2"
);

// Added in 2.30
Event EV_ScriptOrigin_GetAngle
(
"angle",
EV_DEFAULT,
NULL,
NULL,
"get the angles of the entity using just one value.\n"
"Gets the yaw of the entity or an up and down\n"
"direction if newAngle is [0-359] or -1 or -2"
);

CLASS_DECLARATION(ScriptSlave, ScriptOrigin, "script_origin") {
{&EV_Model, &ScriptOrigin::SetModelEvent},
{NULL, NULL }

//
// Added in 2.30
//
{&EV_ScriptOrigin_SetAngle, &ScriptOrigin::SetAngleEvent},
{&EV_ScriptOrigin_GetAngle, &ScriptOrigin::GetAngleEvent},
{NULL, NULL }
};

ScriptOrigin::ScriptOrigin()
Expand All @@ -2115,6 +2145,30 @@ ScriptOrigin::ScriptOrigin()
setSolidType(SOLID_NOT);
}

void ScriptOrigin::SetAngleEvent(Event* ev)
{
float angle;

angle = ev->GetFloat(1);
if (angle == -1) {
ForwardDir = Vector(0, 0, 90);
localangles = Vector(-90, 0, 0);
} else if (angle == -2) {
ForwardDir = Vector(0, 0, -90);
localangles = Vector(90, 0, 0);
} else {
ForwardDir = Vector(0, angle, 0);
localangles = Vector(0, angle, 0);
}

setAngles(localangles);
}

void ScriptOrigin::GetAngleEvent(Event* ev)
{
ev->AddFloat(G_GetAngle(angles));
}

/*****************************************************************************/
/*QUAKED script_skyorigin (1.0 0 0) ?
Expand Down
3 changes: 3 additions & 0 deletions code/fgame/scriptslave.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ class ScriptOrigin : public ScriptSlave
public:
CLASS_PROTOTYPE(ScriptOrigin);
ScriptOrigin();

void SetAngleEvent(Event *ev); // Added in 2.30
void GetAngleEvent(Event *ev); // Added in 2.30
};

class ScriptSkyOrigin : public ScriptSlave
Expand Down

0 comments on commit 8ecbe1d

Please sign in to comment.