- Home /
This code does not work
Hi!
I got this code. I use it for making the weapon sway but it doesn't do anything. I already had another one but this wasn't smooth enaugh, so I tried to implement iTween. Where's the matter in this script?
#pragma strict
public var MoveAmount : float = 1;
public var MoveSpeed : float = 2;
public var GUN: GameObject;
public var MoveOnX : float;
public var MoveOnY : float;
public var DefaultPos : Vector3;
public var NewGunPos : Vector3;
private var go :GameObject;
function Start(){
DefaultPos = transform.localPosition;
go = new GameObject("Weapon Bobbing");
}
function Update(){
MoveOnX = Input.GetAxis("Mouse X") * Time.deltaTime * MoveAmount;
MoveOnY = Input.GetAxis("Mouse Y") * Time.deltaTime * MoveAmount;
iTween.MoveTo(go, iTween.Hash("x",DefaultPos.x + MoveOnX, "y", DefaultPos.y + MoveOnY, "time", MoveSpeed));
GUN.transform.localPosition.x = go.transform.position.x;
GUN.transform.localPosition.y = go.transform.position.y;
}
well for starters you dont want to call iTween.$$anonymous$$oveTo every frame. Call it once and it will move your object for you over the amount of time specified. Since you are calling it every frame you, each iTween instance is overriding the others making it look like it isnt moving.
I believe there is an $$anonymous$$oveUpdate in iTween you may want to look into. Can't remember off the top of my head.
Your answer
Follow this Question
Related Questions
Airplane Sway In Top-Down Game 0 Answers
Pick all gameobject with specific tag 1 Answer
Destruction Help!!!!! 1 Answer
Delay child objects rotation 0 Answers