Pause view/camera after a rotation?

Hell, I’m doing the project Boost lessons, and I’ve decided to make my own as a challenge.
As who doesn’t love a challenge?

My version still a Rocket Lander but in 3D with the right stick on my joypad to rotate the camera around the rocket, and the left joystick to up and rotate the Rocket.

Now, I know this out of the scope of the course, but I wondered how would I make the camera rotate the ship/camera/view 45 Degrees each tap of the right joystick and only do it once or have a delay after each rotation.

I’ve got it to rotate around the ship and I did get it to do 45 Deg jumps, but there was no pause between jumps, so it was unusable.

Here comes my horrible code :wink:

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Movement : MonoBehaviour
{
   float thrustPower = 1000;
   float rotatonThrust = 30;

   Rigidbody rb;
   Camera cam;
   void Start()
   {
       rb = GetComponent<Rigidbody>();

   }


   void Update()
   {

       ProcessInput();
       ProcessRotation();
       ProcessCameraRotation();
   }

   private void ProcessRotation()
   {
       if (Input.GetAxis("Horizontal") < 0)
       {
           RotateMovement(rotatonThrust);
       }
       else if (Input.GetAxis("Horizontal") > 0)
       {
           RotateMovement(-rotatonThrust);
       }
   }

   private void RotateMovement(float direction)
   {
       transform.Rotate(Vector3.forward * direction * Time.deltaTime);
   }

   void ProcessInput()
   {
       if(Input.GetAxis("Vertical") >0 )
       {

           rb.AddRelativeForce(Vector3.up * thrustPower * Time.deltaTime);
       }
      

   }

   void ProcessCameraRotation()
   {
       if (Input.GetAxis("Roll") < 0)
       {

           transform.Rotate(new Vector3(0, Input.GetAxis("Roll") * 1000f * Time.deltaTime, 0));

       }
       if (Input.GetAxis("Roll") > 0)
       {

           transform.Rotate(new Vector3(0, Input.GetAxis("Roll") * 1000f * Time.deltaTime, 0));


       }
   }
}

I know this code is horrible I’ve yet to tidy it up.
If this is too much out of the remit of the course admins please delete it :slight_smile:

Hi,

Good job on challenging yourself. Generally, you are allowed to ask whatever you want here as long as it has to do with game developing. While we teaching assistents cannot always help with problems outside the scope of the course, there are a few students who enjoy looking into other student’s problems and sharing their knowledge.

I don’t know what exactly your desired result is supposed to be but you could probably use Unity’s Euler method. Before you try to get a smooth transition, make your idea with rotating by 45° each time you press the button. Once you accomplished that, you could implement a delay. A coroutine could be interesting. Look it up in the Unity manual. Alternatively, you could work with if-statements and Time.deltaTime to write some kind of a cool-down timer.

Also please feel free to ask our helpful community of students for more ideas over on our Discord chat server.

I hope this helped a bit. :slight_smile:


See also:

Howdy, is this the kind of thing that you’re looking for?

Footage is from an old project I was working on, hopefully get back to it after my current game.
Anyway, here is the code, it rotates the camera 90 degrees with each key press (Q/E), hopefully you can adjust as needed.

public class CamMove : MonoBehaviour
{

    private float targetAngle = 0;
    const float rotationAmount = 7.5f;
    public float rDistance = 1.0f;
    public float rSpeed = 5.0f;



    void Update()
    {

        if (Input.GetKeyDown(KeyCode.Q))
        {
            targetAngle -= 90.0f;
        }
        else if (Input.GetKeyDown(KeyCode.E))
        {
            targetAngle += 90.0f;
        }

        if (targetAngle != 0)
        {
            Rotate();
        }
    }

    protected void Rotate()
    {

        float step = rSpeed * Time.deltaTime;
        float orbitCircumfrance = 2F * rDistance * Mathf.PI;


        if (targetAngle > 0)
        {
            transform.RotateAround(transform.position, Vector3.up, -rotationAmount);
            targetAngle -= rotationAmount;
        }
        else if (targetAngle < 0)
        {
            transform.RotateAround(transform.position, Vector3.up, rotationAmount);
            targetAngle += rotationAmount;
        }       

    }    
}

And as Nina said, you could either have a timer or perhaps have a bool “acceptRotationInput” that is reset when the analogue stick returns to resting postion? So player knocks it right, camera rotates and bool is set to false, stick is moved back to centre, it accepts inputs again?

Hi @Ant that is exactly the look I was going for :smiley:

Thank-you so much.

I will check out your code when I get home

1 Like

No problem buddy, hopefully it helps. :+1:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms