Modify 3rd person camera with Scrollwheel

ArnessoMusicArnessoMusic Posts: 78Member
edited September 2016 in Scripts & Mods
Hey guys,

I am working on TPS game, I made a very simple script what you just add to FPSCamera. It is basic yet, but I will update it when I will start improve this part. Feel free to make it better ;)
Issue: I did not solve the camera's postion will be the in the same position, when you get new States( Run,Jump etc...)
I hope someone will be find useful.
Cheers!
using UnityEngine;
using System.Collections;

public class CameraExtra : MonoBehaviour {

// Use this for initialization
private float camera;
public float scrollspeed = 0.1f;
public float DistMin = -0.4f;
public float DistMax = -4.1f;

void Start(){

camera = GetComponent<vp_FPCamera>().Position3rdPersonOffset.z;
}



// Update is called once per frame
void Update () {
if (Input.GetAxis ("Mouse ScrollWheel") > 0) {
GetComponent<vp_FPCamera> ().Position3rdPersonOffset.z -= GetComponent<vp_FPCamera> ().Position3rdPersonOffset.z * scrollspeed;


}
if (Input.GetAxis ("Mouse ScrollWheel") < 0)
GetComponent<vp_FPCamera> ().Position3rdPersonOffset.z += GetComponent<vp_FPCamera> ().Position3rdPersonOffset.z * scrollspeed;


GetComponent<vp_FPCamera> ().Position3rdPersonOffset.z = Mathf.Clamp (GetComponent<vp_FPCamera> ().Position3rdPersonOffset.z, DistMin, DistMax);
}
}

Comments

  • genocidedolphinsgenocidedolphins Posts: 582Member, MPTester
    edited July 16
    Great script, using it in my game, thank you :) I cleaned it up a little..

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class RSL_UFPSCameraExtra : MonoBehaviour {

    // Use this for initialization
    public float scrollspeed = 0.1f;
    public float DistMin = -0.4f;
    public float DistMax = -4.1f;
    vp_FPCamera myCam;

    void Start()
    {
    myCam = GetComponent<vp_FPCamera>();
    }

    // Update is called once per frame
    void Update()
    {
    if (Input.GetAxis("Mouse ScrollWheel") > 0)
    {
    myCam.Position3rdPersonOffset.z -= myCam.Position3rdPersonOffset.z * scrollspeed;
    }
    if (Input.GetAxis("Mouse ScrollWheel") < 0)
    {
    myCam.Position3rdPersonOffset.z += myCam.Position3rdPersonOffset.z * scrollspeed;
    }
    //myCam.Position3rdPersonOffset.z = Mathf.Clamp(myCam.Position3rdPersonOffset.z, DistMin, DistMax);////this messes up so i turned it off
    }
    }
    Radiant Silver Labs - one man indie band, developing Genocide Dolphins
    Looking for an Android freelancer? Look no further: www.garethmurfin.co.uk
Sign In or Register to comment.