Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Stop Camera movement

Discussion in 'Scripting' started by Bloodember, Jun 20, 2014.

  1. Bloodember

    Bloodember

    Joined:
    Mar 30, 2014
    Posts:
    41
    I've been trying for the past 2 weeks to get my camera to stop moving when it hits an empty gameobject (gameobject has a box collider, the camera does too) and I can't get it to stop. I've done searches on here and on google and I can't come up with a solution. Here's my newest code

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class CameraScript : MonoBehaviour
    6. {
    7.    
    8.    float speed = 2;
    9.    float direction = 1;
    10.  
    11.  
    12.    void Update ()
    13.    {
    14.        
    15.      Vector2 movement = new Vector2 (speed * direction, 0);  
    16.      movement *= Time.deltaTime;
    17.      transform.Translate (movement);
    18.  
    19.      
    20.    }
    21.    void OnTriggerEnter(Collider otherObject)
    22.      {
    23.      if (otherObject.gameObject.tag == "Stop")
    24.      {
    25.        speed = 0;
    26.  
    27.      }
    28.  
    29.      }
    30. }
    31.  
    32.  
    Thanks for the help.
     
  2. Erisat

    Erisat

    Joined:
    Jan 31, 2013
    Posts:
    88
  3. zaxvax

    zaxvax

    Joined:
    Jun 9, 2012
    Posts:
    220
    Erisat likes this.
  4. Bloodember

    Bloodember

    Joined:
    Mar 30, 2014
    Posts:
    41
    Thank you, both of you, I changed it to use the moveCam, which I have done before and it didn't work. What I forgot was the Rigidbody. Now one more question. When the camera stops is just sits there and shakes, how do I get it to stop shaking?


    Edit: I got it, is trigger wasn't checked on my Stop object.
     
    Last edited: Jun 20, 2014