- Home /
Aim Down Sights Positioning Problem
guys, i have a problem, how i make to this script "CHANGE" the x,y,z without "ADDING" the coordinate numbers
example, i put on script to change the xys of a object
y: 0.111 x: 0.111 z: 0.111
and on the object have this xys
y: 0.300 x: 0.300 z: 0.300
the script now make this
y: 0.400 x: 0.400 z: 0.400
i want the object move to xys give by script not add coordinate
( y: 0.111... )
Here is the code:
var applymode : boolean;
var smoothTime : float;
private var velocity = Vector3.zero;
var PositionX : float;
var PositionY : float;
var PositionZ : float;
function Update () {
if(Input.GetButton("Fire2") && !applymode){
//Ajusta as cordenadas para virar "Vector3"
var targetPosition : Vector3 = transform.TransformPoint(Vector3(PositionX,PositionY, PositionZ));
//Pega as cordenadas e faz a mudança de posição :D
transform.position = Vector3.SmoothDamp(transform.position, targetPosition,velocity, smoothTime);
}
if(applymode){
//Ajusta as cordenadas para virar "Vector3"
var targetPositionH : Vector3 = transform.TransformPoint(Vector3(PositionX,PositionY, PositionZ));
//Pega as cordenadas e faz a mudança de posição :D
transform.position = Vector3.SmoothDamp(transform.position, targetPositionH,velocity, smoothTime);
}
}
Answer by Rod-Green · Dec 29, 2011 at 11:36 PM
Try this:
var applymode : boolean;
var smoothTime : float = 1.0f;
private var velocity = Vector3.zero;
var PositionX : float;
var PositionY : float;
var PositionZ : float;
function Apply()
{
//Ajusta as cordenadas para virar "Vector3"
var targetPosition : Vector3 = Vector3.Lerp(transform.position, Vector3(PositionX,PositionY, PositionZ), Time.deltaTime * smoothTime);
//Pega as cordenadas e faz a mudança de posição :D
transform.position = targetPosition;
}
function Update () {
if(Input.GetButton("Fire2") && !applymode){
Apply();
}
if(applymode){
Apply();
}
}
Thanks Rod, bur continue the problem :/ OBS: The code It is within object that is to be moved... The object not stay on the cordenates give by me :/
You're english isn't too clear. Can you please explain the issue more clearly?
i'm trying to make the script move the object with the local coordinates, the script that you have gave to me, he "adds" one coordenate to another
Technically the script I gave you 'overrides' the position to the values given - it doesn't add at all but rather sets it absolutely to the fixed world coordinates.. if you want it to set local you can do something like:
function Apply()
{
//Ajusta as cordenadas para virar "Vector3"
var targetPosition : Vector3 = Vector3.Lerp(transform.localPosition, Vector3(PositionX,PositionY, PositionZ), Time.deltaTime * smoothTime);
//Pega as cordenadas e faz a mudança de posição :D
transform.localPosition = targetPosition;
}
Well, I tested for example, put the same coordinates of the object in the script and stay on same location: D but if I change it will not properly :/
But what I'm trying to do, I move the first gun (For the position of target), I copy the coordinates and put in the script, then put the gun in the usual plac., What happens when I run "apply", the weapon is not in the right place. :/
Your answer
Follow this Question
Related Questions
How do you get the vector3 of one object and assign that vector3 to another object? 1 Answer
UnityEngine.Component:get_transform() Error 1 Answer
How to smooth movement object in one-axis? 1 Answer
how do i move ludo token to right side 0 Answers
Why are my player's positions not being set correctly? 1 Answer