- Home /
player goes crazy when using this, help!
he guys,
this is a little bit of code that has to make the camera go smoothly from one to another point. but it won't work.
could some one tell what i did wrong(i'm not the best at coding at all)
using UnityEngine;
using System.Collections;
public class camerascript : MonoBehaviour {
public Transform target;
public float max;
public float min;
public bool setOn;
public float turnSpeed;
void Start ()
{
turnSpeed = 1f;
}
void Update ()
{
Vector3 smooth = new Vector3(transform.position.x, target.position.y, transform.position.z + Mathf.Lerp(min,max, Time.deltaTime));
cameraPosition();
transform.position = smooth;
}
public void cameraPosition ()
{
if(setOn == false)
{
min = max;
max = 3f;
}
else if(setOn == true)
{
min = max;
max = -3f;
}
}
}
thanx a lot
olivierus
(ow bytheway the Seton == activated in other script :) )
setOn is always true or false, so the last else will never be executed.
the order of your commands is extremely strange. Not sure if this is intended, but every change you make will be used in the following frame.
What does 'Player goes crazy' mean?
@piflik : 1. oke, i fixed that part, thanks for saying. 2. yes like i said i'm not very good at program$$anonymous$$g.
it just goes straight down the ground, and the player won't show up.
Vector3 smooth = new Vector3(transform.position.x, target.position.y, transform.position.z + $$anonymous$$athf.Lerp($$anonymous$$,max, Time.deltaTime));
This tells the object to set the X position to the same, set the Y position to the target's Y position, and then set the Z position to it's current position + a lerped between -3 and 3 based on delta time.
Your object would move continuously in the z axis, flying away in one direction maybe changing direction when you toggle Seton.
@thermalfusion yes that is exactly what happens, but how can i make it that he goes smooth from 1 position on z to the other position on z?
Try using target.position.z ins$$anonymous$$d of transform.position.z, that will at least get rid of the flying-away-part...but I am not sure if the script then does, what you want it to do.