|
|
|
Editor: RED is new, YELLOW is old. This tutorial will show you how to achive a crawling zoom effect, similar to the sniper zoom on the Unreal Tournament sniper rifle. For now lets replace the zoom on the crossbow. Open up crossbow.cpp, jump down to the SecondaryFire() function and delete the content from it (leave the function declaration though). Go back up to the top of the file and add this function to the public section of the class declarations: void ZoomThink(void); This function will be called repeatedly while the weapon is drawn to handle the zooming when you are requesting it. Now add these new public variables in the same area: BOOL NowZooming; BOOL ZoomStopped; These two variables kep track of the current state of the zoom. NowZooming indicated that we are currently zooming and ZoomStopped indicates that the zoom has stopped in progress and needs to be reset on next click. Add the following initilisation code to the CCrossbowBolt::Spawn() function: NowZooming = FALSE; ZoomStopped = TRUE; and add this to the CCrossbowBolt::Deploy() function: SetThink(ZoomThink); pev->nextthink = gpGlobals->time + 0.1; Now for the main function that drives everything. Add this function somewhere in the file: void CCrossbowBolt::ZoomThink() { // Is the player pressing the SecondaryFire button if (m_pPlayer->m_afButtonPressed & IN_ATTACK2) { // Is the player pressing the primaryFire button as well? if (m_pPlayer->m_afButtonPressed & IN_ATTACK) { // If so fire! PrimaryAttack(); } // If we are not currently zooming, and zooming hasn't been // stopped from a previous zoom then start zooming if ((NowZooming == false) && (ZoomStopped == false)) { NowZooming = true; } // If we are currently zooming then change the fov if ((NowZooming == true) && (ZoomStopped == false)) { // If fov is greater than 10 then decrement the fov if (m_pPlayer->m_iFOV > 10) { // Adjust the number of decrements to get // zoom speed to your taste m_pPlayer->m_iFOV--; m_pPlayer->m_iFOV--; } else { // If fov is 10 already then stop zooming ZoomStopped = true; } } // If we are not but ZoomStopped is true then reset the fov if ((NowZooming == false) && (ZoomStopped == true)) { m_pPlayer->m_iFOV = 90; NowZooming = false; ZoomStopped = false; pev->nextthink = gpGlobals->time + 0.25; return; } } // Else SecondaryFire is not held down else { // Player has released the button // Stop zooming and set ZoomStopped if ((NowZooming==true) && (ZoomStopped == false)) { NowZooming = false; ZoomStopped = true; } // Handle the case of releasing the button after zoom // has reached the end and has been automatically stopped if ((NowZooming==true) && (ZoomStopped == true)) { NowZooming = false; ZoomStopped = true; } } // Sets next cycle time pev->nextthink = gpGlobals->time + 0.05; } And thats about it.
Any questions or suggestions should be sent to me:
r.j.pike@Bradford.ac.uk or Alan:
alankemp@bigfoot.com