So Im trying to figure out a simple script that zooms in and out with a gun, Ive already have a base script that uses iTween and it works well, however when I added it to my character gameObject, the whole player moves, not only the camera, which is obviously what i want.
This is the script:
private var Cam : boolean;
Cam = false;
function Update()
{
if (Input.GetButtonDown("Fire2")){
Cam = !Cam;
}
if (Cam == true) {
if (Input.GetButtonDown("Fire2")){
iTween.moveTo(this.gameObject, {"z" : 2.0});
}
}else {
if (Input.GetButtonDown("Fire2")){
iTween.moveTo(this.gameObject, {"z" : 0.0});
}
}
}
So when I click RMB it will move the whole player up 2 units, then back again when I press it again, i need just the camera to do that, not the whole player
Its not that simple, the whole player prefab has different children and such, exactly from the fps tutorial. It goes FirstPersonPlayer > MainCamera (obviously where the camera is, i attached the script there) > PlayerWeapons > Pistol > Gun.
Therefore if i put the script on the main camera, the whole game object including the gun will move.
Well, the law of the land states that moving a transform will move it’s child transforms. You need to not have things parented to the camera for this to work.
You can make generic iTweens in version 2.0 (beta available now) maybe you can use that to iTween a different value in the camera to cause it to zoom via optic changes and not position.
How do i use itween to do optic changes, ive never heard of that term before, is there like a sample of some sort? I didnt seem to see anything along those lines.
The issue about changing the camera to another gameobject just wont work because itll mess up the whole player gameobject and it just wont work, i need a new alternative.
I just mean interpolating some of the other parameters of the camera other than position. You can’t do this with the current version of iTween but the beta is available and you could try using the ValueTo() method that it offers.
Unfortunately nothing seemed to help me there, i tried using this small script that you mentioned in your post
using UnityEngine;
using System.Collections;
public class ZoomScript : MonoBehaviour {
public Transform target;
// Update is called once per frame
void Update(){
if (Input.GetButtonDown("Fire2")){
iTween.LookUpdate(gameObject,target.position,1);
}
}
}
But it doesnt even do anything, and the transform should be a camera but i dont know how to change it, i dont use c# so its a bit more difficult. Were you talking about something different? Cause i didnt see a valueTo method in that thread.
EDIT: Well i just decided to switch from FOV to zoom in so it makes it much easier for me, thanks for the help tho
I was giving you a link to a post I made that gives you a link to the beta version of iTween that I mentioned along with the fact that ValueTo is part of iTween 2.0.
You don’t have to use C# with iTween 2.0, you can put it into your “Plugins” folder (as I mentioned in that link I sent you).
If you do manage to get iTween 2.0 beta from that link and put it into a “Plugins” folder you can do this to animate the field of view (in .JS):
function Start () {
//Zoom the field of view in:
iTween.ValueTo(gameObject,{"from":60,"to":30,"time":2,"onupdate":"animateFieldOfView","easetype":"easeinoutcubic"});
//Zoom the field of view out:
iTween.ValueTo(gameObject,{"from":30,"to":60,"time":2,"delay":2.5,"onupdate":"animateFieldOfView","easetype":"easeinoutcubic"});
}
//Apply the field of view to the main camera:
function animateFieldOfView(newFieldOfView : float){
camera.main.fieldOfView = newFieldOfView;
}
Assets/ZoomScript2.js(3,11): BCE0019: 'ValueTo' is not a member of 'iTween'.
I got that error, and yes i do have the itween js file in my game.
EDIT: Well i figured out an alternative, its not the best or the most effecient one but it works and zooms in / out smoothly, so no need for itweens in this script for now, Thanks again for all the help