Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0

Zoom weapon camera Script


Hi everyone 

i have problem with this Script its not working with unity5 and give me Error

please fix the script for me thanks 

sorry for my English 

var HipPose : Vector3;
var AimPose : Vector3;
var AimSpeed = 15;
private var MainCam : GameObject;
private var WeapCam : GameObject;

function Start () 
        transform.localPosition = HipPose;
        MainCam = GameObject.FindGameObjectWithTag("MainCamera");
        WeapCam = GameObject.FindGameObjectWithTag("WeaponCamera");

function Update () 
           MainCam.camera.fieldOfView = 50;
//         transform.localPosition = AimPose;
           transform.localPosition = Vector3.Lerp(transform.localPosition,AimPose,AimSpeed*Time.deltaTime);

// transform.localPosition = HipPose;
        MainCam.camera.fieldOfView = 60;
        transform.localPosition = Vector3.Lerp(transform.localPosition,HipPose,AimSpeed*Time.deltaTime);



Share this post

Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

can you tell us what error it showes in the console ? 


guess:  -try replacing "transform.localPosition" with "this.transform.position"

           -also i think that you dont need to change the local transform at all since the change of the fov already gives you a pretty solid zoom effect and changing the camera position could lead to clipping problems



Edited by Erarnitox

Share this post

Link to post
Share on other sites

  • 0

thanks i found another scripts  solved my problem that's it 

var Cam : Camera;
var AimPos : Vector3;
var NormalPos : Vector3;
var Gun : GameObject;

function Start () {
if(Cam == null) {
Cam = Camera.main;

function Update () {
Gun.transform.localPosition = Vector3.Lerp(Gun.transform.localPosition, AimPos, Time.deltaTime * 8);
Cam.fieldOfView = Mathf.Lerp(Cam.fieldOfView, 45, Time.deltaTime * 10);
Gun.transform.localPosition = Vector3.Lerp(Gun.transform.localPosition, NormalPos, Time.deltaTime * 8);
Cam.fieldOfView = Mathf.Lerp(Cam.fieldOfView, 60, Time.deltaTime * 10);

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...