Polyobjects with simulated inertia.

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
Super Chex
Posts: 8
Joined: Mon Jul 11, 2011 11:28 am

Polyobjects with simulated inertia.

Post by Super Chex »

Hello, everyone.

I've been trying to create player-controlled vehicles in the form of complex polyobjects. I've successfully managed to control the angle and linear movement of the polyobject, but when I went to add inertia, I messed up badly, to the point where the polyobject would behave entirely erratically. I tried many things to try and correct the behavior, but in doing so I made it even more broken and messy. I have sent hours pouring over the ZDoom Wiki, but nothing in there seems to directly address my use case.

Working ACS (pardon the mess):

Code: Select all

#include "zcommon.acs"

int rc_car_angle = 0;
int rc_car_speed = 0;
int rc_car_max_speed = 16;
int rc_car_momentum = 0;
int rc_car_rotate_speed = 4;
bool rc_car_active = 0;

// Proper starting and Stopping.

Script "RCStart" (void)
{

        SetPlayerProperty (0, 1, PROP_TOTALLYFROZEN);
        ChangeCamera (1, 0, 0);
        rc_car_active = 1;
        ACS_NamedExecute ("RCLogic",0);

}

Script "RCStop" (void)
{

        SetPlayerProperty (0, 0, PROP_TOTALLYFROZEN);
        ChangeCamera (0, 0, 0);

}

// Main logic loop.

Script "RCLogic" (void)
{
        while ( rc_car_active == 1 )
        {

                int buttons = GetPlayerInput(-1, INPUT_BUTTONS);
                Delay (1);
                if (buttons & BT_MOVELEFT)
                {
                        ACS_NamedExecute ("RCTurnLeft",0);
                }

                if (buttons & BT_MOVERIGHT)
                {
                        ACS_NamedExecute ("RCTurnRight",0);
                }

                if (buttons & BT_FORWARD)
                {
                        ACS_NamedExecute ("RCMoveForward",0);
                }

                if (buttons & BT_BACK)
                {
                        ACS_NamedExecute ("RCMoveBackward",0);
                }

                if (buttons & BT_USE)
                {
                        rc_car_active = 0;
                }

        }
        ACS_NamedExecute ("RCStop",0);
}

// RC functions.

Script "RCTurnLeft" (void)
{

        Polyobj_OR_RotateLeft (0, 32, 0+rc_car_rotate_speed);
        rc_car_angle+=rc_car_rotate_speed;

}

Script "RCTurnRight" (void)
{

        Polyobj_OR_RotateRight (0, 32, 0+rc_car_rotate_speed);
        rc_car_angle-=rc_car_rotate_speed;

}

Script "RCMoveForward" (void)
{

        Polyobj_OR_Move (0, 16, rc_car_angle, rc_car_max_speed);

}

Script "RCMoveBackward" (void)
{

        Polyobj_OR_Move (0, 16, rc_car_angle+128, rc_car_max_speed);

}
Broken version (again, sorry):

Code: Select all

#include "zcommon.acs"

int rc_car_angle = 0;
int rc_car_speed = 0;
int rc_car_max_speed = 16;
int rc_car_is_moving = 0; // 0 (Not moving.), 1 (Moving forward.), -1 (Moving backward.)
int rc_car_momentum = 0;
int rc_car_rotate_speed = 0;
int rc_car_rotate_dividend = 4; //rotation will be divided by this variable's value.
bool rc_car_active = 0;

// Proper starting and Stopping.

Script "RCStart" (void)
{

        SetPlayerProperty (0, 1, PROP_TOTALLYFROZEN);
        ChangeCamera (1, 0, 0);
        rc_car_active = 1;
        ACS_NamedExecute ("RCLogic",0);

}

Script "RCStop" (void)
{

        SetPlayerProperty (0, 0, PROP_TOTALLYFROZEN);
        ChangeCamera (0, 0, 0);

}

// Main logic loop.

Script "RCLogic" (void)
{
        while ( rc_car_active == 1 )
        {				
                int buttons = GetPlayerInput(-1, INPUT_BUTTONS);
                Delay (1);
                if (buttons & BT_MOVELEFT)
                {
                        ACS_NamedExecute ("RCTurnLeft",0);
                }

                if (buttons & BT_MOVERIGHT)
                {
                        ACS_NamedExecute ("RCTurnRight",0);
                }

                if (buttons & BT_FORWARD)
                {
                        ACS_NamedExecute ("RCMoveForward",0);
                }

                if (buttons & BT_BACK)
                {
                        ACS_NamedExecute ("RCMoveBackward",0);
                }

                if (buttons & BT_USE)
                {
                        rc_car_active = 0;
                }

				if ( rc_car_is_moving == 0 )
                {
                        if ( rc_car_speed >= 0 )
						{
						rc_car_rotate_speed = rc_car_speed / rc_car_rotate_dividend;
                        rc_car_speed-=1;
						}
                }
				rc_car_is_moving = 0;
        }
        ACS_NamedExecute ("RCStop",0);
}

// RC functions.

Script "RCTurnLeft" (void)
{

        Polyobj_OR_RotateLeft (0, rc_car_rotate_speed, rc_car_angle);
        rc_car_angle+=rc_car_rotate_speed;

}

Script "RCTurnRight" (void)
{

        Polyobj_OR_RotateRight (0, rc_car_rotate_speed, rc_car_angle);
        rc_car_angle-=rc_car_rotate_speed;

}

Script "RCMoveForward" (void)
{
		rc_car_is_moving = 1;
		if ( rc_car_speed <= rc_car_max_speed )
		{
				rc_car_speed+=1;
		}
        Polyobj_OR_Move (0, rc_car_speed, rc_car_angle, rc_car_speed);

}

Script "RCMoveBackward" (void)
{
		rc_car_is_moving = -1;
		if ( rc_car_speed <= rc_car_max_speed )
		{
				rc_car_speed+=1;
		}
        Polyobj_OR_Move (0, rc_car_speed, rc_car_angle+128, rc_car_speed);

}
Here's the map for testing:
https://drive.google.com/open?id=1reulc ... 4XudfoNcl7

You'll need to run

Code: Select all

pukename RCStart
in order to use the RC car.

Return to “Scripting”