Author Topic: Set Field-of-View (Fov)  (Read 2138 times)

In the server.cs file of a gun, in the //weapon image section, I added the code
Code: [Select]
setFov = 30;to try to make the field of view zoom in a little when using the weapon.

So part of my weapon image code now looks like this...

Code: [Select]
//weapon image

   mountPoint = 0;
   offset = "0 0 0";
   eyeOffset="0 0.9 -0.07";
   rotation = eulerToMatrix( "0 0 0" );
   setFov = 30;

The problem is, nothing happens in the game.

How do I change field of view when a weapon is out?


---

Edit: Solved thanks to Munkey

Final code solution:

Code: [Select]
function MP40Image2::onMount(%this,%obj,%slot)
{
setFov(30);
}

function MP40Image2::onUnMount(%this,%obj,%slot)
{
setFov(90);
}
« Last Edit: December 01, 2011, 11:34:51 PM by EpicFrySauce »

you have to call it when the weapon is equipped, you added a command to a set of values for other things

you have to call it when the weapon is equipped, you added a command to a set of values for other things


Ah, thank you. So I write a small function for that? I'm quite new to programming so if you could provide a quick code example, that would be great.

You would either need client-side coding or a separate player datablock for use with the gun to make this work.

Crap, guys I'm sorry. I really don't know what to do here. Can someone just make a code example?

I did try something like

Code: [Select]
datablock gunImage::onActivate(FovChange)
{
setFov = 30;
}

and yes, it was a fail.
« Last Edit: December 01, 2011, 10:25:42 PM by EpicFrySauce »

Code: [Select]
datablock gunImage::onActivate(FovChange)
{
setFov(30);
}
?

Code: [Select]
datablock gunImage::onActivate(FovChange)
{
setFov(30);
}
?

Hang on Ima try that...

Edit: No... that didn't work either. I know this isn't that hard to do... I just don't have the details to do it.
« Last Edit: December 01, 2011, 09:37:47 PM by EpicFrySauce »

You would either need client-side coding or a separate player datablock for use with the gun to make this work.
Nope.


Code: [Select]
function gunImage::onMount(%this,%obj,%slot)
{
%client = %obj.client;
%client.setControlCameraFov(23);
parent::onMount(%this,%obj,%slot);
}

function gunImage::onUnMount(%this,%obj,%slot)
{
%client = %obj.client;
%client.setControlCameraFov(90);
parent::onUnMount(%this,%obj,%slot);
}


If you need more help, the AWP changes zoom when you go to sights, and back out when you exit. It is a very poorly scripted gun, however, because I didn't know what I was doing back then.

Nope.


Code: [Select]
function gunImage::onMount(%this,%obj,%slot)
{
%client = %obj.client;
%client.setControlCameraFov(23);
parent::onMount(%this,%obj,%slot);
}

function gunImage::onUnMount(%this,%obj,%slot)
{
%client = %obj.client;
%client.setControlCameraFov(90);
parent::onUnMount(%this,%obj,%slot);
}


If you need more help, the AWP changes zoom when you go to sights, and back out when you exit. It is a very poorly scripted gun, however, because I didn't know what I was doing back then.

Thanks! That worked. You won the topic. To get good at stuff like that... would probably take a while...

To get good at stuff like that... would probably take a while...

It just takes time and patience. It also helps if you know any other coding languages (sadly I don't, only torque).

Definitely. I would say I am pretty patient... I've been at this (making a weapon) for a few weeks... although, it seems like just when I'm about to get somewhere, I fail... and have to ask for help again. :P

I changed up the code you gave me so that when I look down the iron sights of my gun, then it zooms in. I also changed the Fov code back to "setFov" for a smooth transition. Thanks again!

That is a great idea. I hope it turns out well.

That is a great idea. I hope it turns out well.

Thanks Extrude! So far, it's turning out great... and I used your tutorial to add in my iron sights. :)