- Home /
Vector3 Transform.Position Not Working
In the script below when facing left is true I want my GameObject (the one this script is attached to) to reset its y position and then move it to the right while keeping its new y position. So on play give object a random y position within two specified points and then while keeping that new y position move it to the right. But Vector 3 will not allow me to assign a transform.position to it and gives me the error below.
Script:
#pragma strict
var bounceControllerScript : Bounce_Controller_Script;
var objectsOriginalPos : Vector3;
public var smooth : float;
private var newPosition : Vector3;
var stopPositioningTrigger = false;
function Awake ()
{
gameObject.transform.position.x = -8;
objectsOriginalPos = transform.position;
}
function Update ()
{
PositionChanging();
}
function PositionChanging ()
{
if (Bounce_Controller_Script.facingLeft == true)
{
var newPosition : Vector3 = new Vector3(-2.68, objectsOriginalPos, 0);
transform.position = Vector3.Lerp(transform.position, newPosition, smooth * Time.deltaTime);
}
}
Error
BCE0024: The type 'UnityEngine.Vector3' does not have a visible constructor that matches the argument list '(float, UnityEngine.Vector3, int)'.
Answer by fueldown · Aug 26, 2014 at 06:37 PM
You are not passing the right values to the new vector3.
Try changing this:
var newPosition : Vector3 = new Vector3(-2.68, objectsOriginalPos, 0);
To this:
var newPosition : Vector3 = new Vector3(-2.68, objectsOriginalPos.y, 0.0);
Answer by AyAMrau · Aug 26, 2014 at 06:37 PM
you are using the whole objectsOriginalPos : Vector3 as the Y component in the new call. You should access the Y component of the position:
new Vector3(-2.68, objectsOriginalPos.y, 0)
Your answer
Follow this Question
Related Questions
Position of a GameObject 2 Answers
Finding Distances With Vector3 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
Getting an Objects position once 2 Answers