Sniper Rifle with UFPS

If you are using the Mobile Add-On, follow this link.

Hello all. I’m back again with another video. This time, I made a sniper rifle video and am including the below script. I hope this is helpful to all. Also, please click some ads if you like the videos and want me to do more.

Nothing super fancy with the Script, but I actually like how well it works. Especially since I did not have to change any scripts that come with UFPS.

FYI – I just added the ability to Zoom in and out based on Mouse Scroll Wheel
NOTE = UNCOMMENT LINES 39 and 54 if you are using UFPS 1.5

using UnityEngine;
using System.Collections;

public class SniperScript : MonoBehaviour {

//DefaultCrosshair
public Texture DefaultCrosshair = null;//Default Crosshair - use UFPS
public Texture SniperCrosshair=null;//Sniper Crosshair - make your own
public float FieldOfViewSetting=9f;//Maxmium Zoom amount
public float fovMultiplier=2f;


protected vp_FPPlayerEventHandler m_Player = null;
protected vp_SimpleCrosshair m_crosshair=null;
protected vp_FPCamera m_camera=null;
Camera myCamera=null;

float DefaultFOV=60f;//Default FieldOfView that your weapon is set to
float maxFOV=60f;//Maximum FieldOfView will equal the DefaultFOV. You may want to cut this in half
public float tempFOV=0f;//Temporary holder for the current Field of View

protected virtual void Awake()
{

m_Player = GameObject.FindObjectOfType(typeof(vp_FPPlayerEventHandler)) as vp_FPPlayerEventHandler; // cache the player event handler
m_crosshair = GameObject.FindObjectOfType(typeof(vp_SimpleCrosshair)) as vp_SimpleCrosshair; // cache the Simple Crosshair
m_camera = GameObject.FindObjectOfType(typeof(vp_FPCamera)) as vp_FPCamera; // cache the Simple Crosshair
myCamera=m_camera.GetComponent<Camera>();
DefaultFOV=m_camera.RenderingFieldOfView;
maxFOV=DefaultFOV;

}

void OnGUI ()
{
if(m_Player.Zoom.Active)
{
m_Player.Crosshair.Set(SniperCrosshair);
// m_crosshair.HideOnFirstPersonZoom=false;//UNCOMMENT THIS FOR UFPS 1.5
tempFOV+=Input.GetAxis("Mouse ScrollWheel")*-fovMultiplier;//Assign temp zoom times -2. Scroll forward zoom in. Raise or lower -2 for quicker zooming
//Handle the Zooming using the Mouse ScrollWheel.

if(tempFOV>=maxFOV)//IF we have reached the Maximum, then don't zoom out anymore. Might want to cut it in half here
tempFOV=maxFOV;
else if(tempFOV<=FieldOfViewSetting)//If we reached closest zoom level, then stop zooming in
tempFOV=FieldOfViewSetting;
m_camera.RenderingFieldOfView=tempFOV;//Apply our Zoom amount
myCamera.fieldOfView=tempFOV;

}
else
{
m_crosshair.m_ImageCrosshair=DefaultCrosshair;
// m_crosshair.HideOnFirstPersonZoom=true; //UNCOMMENT THIS FOR UFPS 1.5
m_camera.RenderingFieldOfView=DefaultFOV;
}
}
}

Below is my Zoom Settings – basically the same as Pistol Zoom. Feel free to copy the other settings off the video at the end.


///////////////////////////////////////////////////////////
// Component Preset Script
///////////////////////////////////////////////////////////

ComponentType vp_FPWeapon
ShakeSpeed 0.05
ShakeAmplitude 0.5 0 0
PositionOffset 0 -0.58 0.17
RotationOffset 0.4917541 0.015994 0
PositionSpringStiffness 0.055
PositionSpringDamping 0.45
RotationSpringStiffness 0.025
RotationSpringDamping 0.35
RenderingFieldOfView 9
RenderingZoomDamping 0.2
BobAmplitude 0.5 0.4 0.2 0.005
BobRate 0.8 -0.4 0.4 0.4
BobInputVelocityScale 15
PositionWalkSlide 0.2 0.5 0.2

HeaderWP

Advertisements

2 thoughts on “Sniper Rifle with UFPS”

  1. Hello my home image does not appear but the other takes you know why? sorry for the spelling (google translation)

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s