This member has provided no bio about themself...

Report article RSS Feed ScrGold/Coding: view acceleration for trigger_camera

Posted by PanSartre on Apr 15th, 2013

You want to script a nice camera intro in HL but the rotating speed is too slow? Here is the easy way to set the view acceleration for trigger_camera in hammer by adding a new variable in the SDK. (new entries are bold)

Open triggers.cpp and introduce a new variable like this:
[...]
float m_acceleration;
float m_deceleration;
float m_viewacceleration;
int      m_state;
[...]

The game should be able to save the new variable:
[...]
DEFINE_FIELD( CTriggerCamera, m_acceleration, FIELD_FLOAT ),
DEFINE_FIELD( CTriggerCamera, m_deceleration, FIELD_FLOAT ),
DEFINE_FIELD( CTriggerCamera, m_viewacceleration, FIELD_FLOAT ),
DEFINE_FIELD( CTriggerCamera, m_state, FIELD_INTEGER ),
[...]

Add a new keyvalue (for hammer):
[...]
    else if (FStrEq(pkvd->szKeyName, "deceleration"))
    {
        m_deceleration = atof( pkvd->szValue );
        pkvd->fHandled = TRUE;
    }
    else if (FStrEq(pkvd->szKeyName, "viewacceleration"))
    {
        m_viewacceleration = atof( pkvd->szValue );
        pkvd->fHandled = TRUE;
    }

    else

        CBaseDelay::KeyValue( pkvd );
[...]

Go to the spawn function and add this:
[...]
    if ( m_acceleration == 0 )
        m_acceleration = 500;
    if ( m_deceleration == 0 )
        m_deceleration = 500;
    if ( m_viewacceleration == 0 )
        m_viewacceleration = 40;

}
[...]


Here comes the importent part in function CTriggerCamera::FollowTarget( ). Go to:
    pev->avelocity.x = dx * 40 * gpGlobals->frametime;
    pev->avelocity.y = dy * 40 * gpGlobals->frametime;
and change it to:
    pev->avelocity.x = dx * m_viewacceleration * gpGlobals->frametime;
    pev->avelocity.y = dy * m_viewacceleration * gpGlobals->frametime;

At least add the new keyvalue in your fdg-file at the trigger_camera entity:

[...]
    speed(string) : "Initial Speed" : "0"
    acceleration(string) : "Acceleration units/sec^2" : "500"
    deceleration(string) : "Stop Deceleration units/sec^2" : "500"
    viewacceleration(string) : "View Acceleration" : "40"
[...]

That's it!

Here is my example:

with default value:

Post a Comment
click to sign in

You are not logged in, your comment will be anonymous unless you join the community today (totally free - or sign in with your social account on the right) which we encourage all contributors to do.

2000 characters limit; HTML formatting and smileys are not supported - text only

Level
93%
Gamer
7
Avatar
Avatar
Offline Since
Aug 15, 2014
Country
Germany Germany
Gender
Male
Member Watch
Track this member
Blog
Browse
Blogs
Report Abuse
Report article