Cube rotation and force

Hi guys. I’m trying to create a game similiar to “Ahtung! Die Kurve”.
I’m trying to get those cubes to rotate with “a” and “d” buttons but it happends very slow.
Please help me to get rid of that problem.

Here is my code for movement:

void Update()
    {
        if (networkView.isMine)
        {
            InputMovement();
            InputColorChange();
        }
        else
        {
            SyncedMovement();
        }
		
	//===Force===========================
		
	transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);	
		
	
    }

	//===Movement========================================
    public void InputMovement()
    {
		
        
        /*if(Input.GetKey(KeyCode.DownArrow))
            transform.Translate(-Vector3.forward * moveSpeed * Time.deltaTime);
        
        if(Input.GetKey(KeyCode.LeftArrow))
            transform.Rotate(Vector3.up, -turnSpeed * Time.deltaTime);
        
        if(Input.GetKey(KeyCode.RightArrow))
            transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);
		
		*/
		 if(Input.GetKey(KeyCode.W)) 
       transform.Translate(Vector3.forward * Time.deltaTime * moveSpeed);
 
       if(Input.GetKey(KeyCode.S)) 
       transform.Translate( -1 * Vector3.forward * Time.deltaTime * moveSpeed);
 
       if(Input.GetKey(KeyCode.A)) 
       transform.Rotate(0,-1,0); 
 
       if(Input.GetKey(KeyCode.D)) 
       transform.Rotate(0,1,0); 
		
    }

2 Answers

2

Your code for ‘A’ and ‘D’ rotation should just like the you have comment out for LeftArrow and RightArrow. Replace lines 41 - 45 with:

if(Input.GetKey(KeyCode.A))
    transform.Rotate(Vector3.up, -turnSpeed * Time.deltaTime);
 
if(Input.GetKey(KeyCode.D)
    transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);

The ‘turnSpeed’ variable controls the speed of the turn. If ‘turnSpeed’ is a public variable, then you must make the change in the Inspector. Changing the value in the script will not change the value used by the component. If you’ve copied and pasted this code, you will need to declare a ‘turnSpeed’ variable and give it an initial value.

Note you can also use something similar to the code you already have:

   if(Input.GetKey(KeyCode.D)) 
       transform.Rotate(0,turnSpeed * Time.deltaTime,0);

Ok i changed value in inspector. Can you tell me what assigning a value in script doesn't work?

Thank You :wink: