Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Orbit around invisible object on ground, always at camera forward position

Discussion in 'Scripting' started by sTorrr, Nov 9, 2018 at 2:39 PM.

  1. sTorrr

    sTorrr

    Joined:
    Oct 28, 2018
    Posts:
    34
    Is it possible to make an invisible object always appear on ground layer at camera forward position then rotate around it using this as transform object? #child, #pivot, #cameraHolder
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    1,746
    Parent the camera to an invisible GameObject and then set the local Z position of your camera object to the distance you want to orbit the invisible object at. Rotate the invisible object to pan around.
     
    sTorrr likes this.
  3. sTorrr

    sTorrr

    Joined:
    Oct 28, 2018
    Posts:
    34
    How would I make this child object trace the ground if it’s locked on static offset on camera local z axis. If I zoom in on camera local z-axis, I want object not to go through ground, maybe using colliders or something. When I zoom out, I do not want child object to leave ground and follow camera in air on camera local z-axis. Child object always tracing ground. Would it be possible to shoot out a ray or something?
     
  4. sTorrr

    sTorrr

    Joined:
    Oct 28, 2018
    Posts:
    34
    This RTScamera asset, link bellow, is exactly what I am trying to make. You can see how the green ball always remain in center of camera regardless of zoom on camera local z-axis, demo below. It says documentation and source included. Does this mean I can watch every script to learn?

    You can see LookAt, green ball, is climbing on the green objects, but not on the blue walls or red piles. Is this due to collision settings?

    Demo:
    http://voxelfrog.azurewebsites.net/Demos/Public/RTSCameraPro/index.html

    Asset:
    https://www.assetstore.unity3d.com/en/?stay#!/content/10390
     
  5. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    1,746
    You move the child (the camera)'s local position to zoom in and out. You move the parent (the invisible object) to translate the camera. You rotate the parent to orbit the camera. If you add a collider and rigidbody to the parent, and use rigidbody.MovePosition() to avoid physical forces, your object will not go through walls.

    Logic for obstruction detection on the child (the actual camera) would be more involved. There are examples in the Standard Assets pack. You may consider using Cinemachine as well. Both are free.