hi guys,
i am making a project out of the unity jump start tutorial:
http://forum.unity3d.com/viewtopic.php?t=28433&postdays=0&postorder=asc&start=0
all is identical except for the cube wich is for me a little 3d model and for the script wich is not exactly the same as i put :
if(Input.GetKeyDown("right")){
transform.Rotate(Vector3.up, 50, Space.World);
}
if(Input.GetKeyUp("right")){
transform.Rotate(Vector3.up, -50, Space.World);
}
if(Input.GetKeyDown("left")){
transform.Rotate(Vector3.down, 50, Space.World);
}
if(Input.GetKeyUp("left")){
transform.Rotate(Vector3.down, -50, Space.World);
}
to make the plane rotate a little bit when he goes right or left.
my problem is: after making the plane go 3-4 times right and left he is just not displayed anymore.
he dont disappear totally as i can still see him into the scene window.
so why ? why does he disappear ? is there a better way to make the little rotation for my plane?
thx
After the plane disappears, try going to the scene view and selecting the plane object. If you move your mouse over the scene and press the F key, the display will zoom to where the plane is. Check to see if the plane has really disappeared (ie, the geometry has gone) or if it has just moved offscreen. In any case, the left/right turn code you have just posted is probably not what is causing the problem. Perhaps you could post the rest of the script if you don’t get to the bottom of this.
in fact its more a kind of display problem, the geometrie as i said does not disappear.
1 Like
entire code here, can somebody help me please ?
is this an unity display bug or something ?
var playerSpeed : int = 70;
var playerLives: int;
static var playerScore : int;
var bullet: Rigidbody;
function Update () {
// amount to move playerSpeed
amtToMoveX = (playerSpeed * Input.GetAxis("Horizontal")) * Time.deltaTime;
amtToMoveY = (playerSpeed * Input.GetAxis("Vertical")) * Time.deltaTime;
// move/translate playerSpeed
transform.Translate(Vector3.right * amtToMoveX);
transform.Translate(Vector3.down * amtToMoveY);
if(Input.GetKeyDown("right")){
transform.Rotate(Vector3.up, 50, Space.World);
}
if(Input.GetKeyUp("right")){
transform.Rotate(Vector3.up, -50, Space.World);
}
if(Input.GetKeyDown("left")){
transform.Rotate(Vector3.down, 50, Space.World);
}
if(Input.GetKeyUp("left")){
transform.Rotate(Vector3.down, -50, Space.World);
}
if(Input.GetKeyDown("space") ){
var tempBullet : Rigidbody;
tempBullet = Instantiate(bullet, transform.position, Quaternion.identity );
}
}
function OnGUI(){
GUI.Label(Rect(10,10,200,50),"Score: " + playerScore);
GUI.Label(Rect(10,30,200,50),"Lives: " + playerLives);
}
I have had this problem with object that have animation attached to it when imported even thought they don’t have any animation. If it has an animation component try removing it and see what happens.
when i attach the script to a simple cube there is the same problem, try at home, and tell me please.
I’ve tested the script - the object doesn’t disappear, but it rapidly moves off-camera. I think the issue is that transform.Translate moves the object relative to its own coordinate axes, so if you use Vector3.right, it will move to the object’s right, whatever that is. Using this translation and rotation simultaneously like this will tend to make the object move in an uncontrolled way. I would imagine that the behaviour you want would be achieved by translating the object forward each frame and then letting the keys control rotation only.
damn, i dont understand !
any code exemple ?
thx
Well it doesn’t fly away for me and key are responsive what are you trying to do?
Ok I see try this
//transform.Translate(Vector3.right * amtToMoveX);
//transform.Translate(Vector3.down * amtToMoveY);
if(Input.GetKeyDown("right")){
transform.Rotate(Vector3.up*50);
}
if(Input.GetKeyUp("right")){
transform.Rotate(Vector3.up*-50);
}
if(Input.GetKeyDown("left")){
transform.Rotate(Vector3.down* 50);
}
if(Input.GetKeyUp("left")){
transform.Rotate(Vector3.down*-50);
}
the thing that is causing the most issues at the moment is the first 2 lines i commented out, try this and see if its a little more of what you are looking for. try saving the lines commented out to variables and then using the variables in your movement.