i try and rotate and strange things happen
I try and rotate a cube every time the space bar is pressed as well as the cube jumping. However what happens is it rotates 180 degrees instead of 90 and doesnt rotate again after the first jump, i have no clue why on earth this is happening, ive tried everything, this is my code:
using UnityEngine;
using System.Collections;
public class Movement : MonoBehaviour {
public GameObject Box;
public Vector3 BoxRot;
public float BoxX;
public float BoxY;
public float BoxZ;
public float JumpHeight=100f;
public Vector3 JumpTo;
public GameObject floor;
public bool jumping=false;
public float CurX;
public string FloorTag = "Floor";
public Rigidbody CubeRigidBody;
public GameObject NonRotCube;
public Vector3 NonRotCubeVec3 = new Vector3(0,0,1);
public Quaternion CurrentPos;
void Jump()
{
CubeRigidBody.AddForce (Vector3.up * 250f);
//Box.transform.rotation = Quaternion.Slerp (CurrentPos,new Quaternion(CurrentPos.x + 90,CurrentPos.y,CurrentPos.z,0),10 );
Box.transform.Rotate (Vector3.left,90,Space.World);
}
void OnCollisionEnter(Collision Col)
{
if (Col.gameObject.name == "Floors")
{
jumping = false;
}
}
void OnCollisionStay (Collision Col1)
{
if (Col1.gameObject.name == "Floors")
{
jumping = false;
}
}
void OnCollisionExit (Collision Col2)
{
if (Col2.gameObject.name == "Floors")
{
jumping = true;
}
}
void Sideways()
{
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
CurX = Box.transform.position.x;
Box.transform.position = Vector3.Lerp(new Vector3(CurX,Box.transform.position.y, Box.transform.position.z), new Vector3(CurX-35, Box.transform.position.y, Box.transform.position.z),2*Time.deltaTime);
}
if (Input.GetKeyDown(KeyCode.RightArrow))
{
CurX = Box.transform.position.x;
Box.transform.position = Vector3.Lerp(new Vector3(CurX, Box.transform.position.y, Box.transform.position.z), new Vector3(CurX + 35, Box.transform.position.y, Box.transform.position.z), 2 * Time.deltaTime);
}
}
void Update ()
{
if(jumping)
{
Box.transform.rotation = Quaternion.Slerp(new Quaternion(Box.transform.rotation.x,Box.transform.rotation.y,Box.transform.rotation.z,0),new Quaternion(Box.transform.rotation.x,0,0,0),1);
}
Sideways();
//Box.transform.Translate ( Vector3.forward * 10f * Time.deltaTime);
Box.transform.Translate (new Vector3(0,0,10 * Time.deltaTime),Space.World);
BoxY = Box.transform.position.y;
JumpTo = new Vector3 (0, JumpHeight, Box.transform.position.y);
if (Input.GetKeyDown ("space") && !jumping)
{
//Box.transform.Translate(Vector3.up * 100 * Time.deltaTime, Space.World);
CurrentPos = new Quaternion(Box.transform.rotation.x,Box.transform.rotation.y,Box.transform.rotation.z,0);
Jump();
}
}
}
Comment
i dont think its conflicting with any other scripts, any solutions?
Your answer
Follow this Question
Related Questions
How to smoothly rotate an object 180 degrees each time you press the spacebar in 3D 0 Answers
How to prevent NavMeshAgent from rotate? 1 Answer
Rotate an object when two others collide? 1 Answer
How to translate an object in an unknown angle ? 1 Answer
Applying a rotation relative to the object's starting rotation 0 Answers