Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by connoradams251 · Sep 20, 2019 at 02:58 PM · cameracamera-movementtransform.positionracingtransform.rotate

How do I get camera movement through controller input.

I tried adding the movement to the existing Vector3 but I didn't want it to keep going. I also didn't really want to use a bounding box to stop the camera, I think that would be clunky/glitchy. I am trying to get this effect from the camera. Any help is appreciated. I also would like to be able to add the rotation effect, but the main problem I am having is the position. The problem with the position is that with this it literally doesn't do anything. Any solutions?

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class CameraSwitcher : MonoBehaviour
 {
     [SerializeField] GameObject CockpitCamera;
     [SerializeField] GameObject ChaseCamera;
     bool CockpitCameraActive = true;
     bool ChaseCameraActive = false;
 
     Vector3 ChaseCameraPos;
 
     void Update()
     {
         if(Input.GetKeyDown(KeyCode.C))
         {
             if(CockpitCamera.active)
             {
                 CockpitCamera.SetActive(false);
                 ChaseCamera.SetActive(true);
             }
             else if (ChaseCamera.active)
             {
                 CockpitCamera.SetActive(true);
                 ChaseCamera.SetActive(false);
             }
         }
 
         if (ChaseCamera.active)
         {
             float h = Input.GetAxis("Horizontal");
             ChaseCameraPos = ChaseCamera.transform.position;
             ChaseCameraPos = new Vector3(h, 1.41f, -4.367f);
         }
     }
 }



Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TreyH · Sep 20, 2019 at 03:20 PM 0
Share

Well, you aren't using ChaseCameraPos anywhere, yeah? This might be a simplified version of your actual script, but that's not being assigned to a transform as a position and it's not accessibly externally since it's a private value.

For that effect, I think you have the right idea that the camera's position can be taken from the actual stick direction (turning Right, the camera should strafe to the Right), but you'll want the camera's focus to be some point in front of the vehicle. Attaching a crude paint drawing.
alt text

car.png (12.3 kB)
avatar image connoradams251 TreyH · Sep 20, 2019 at 05:47 PM 0
Share

Lol! First of all, I can't believe I made such a simple mistake. Second, thank you for your help, though I've tried a lot of things and cannot seem to implement what you are saying here. I might have to try something else.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by SuperScience · Sep 20, 2019 at 06:46 PM

Hi Connor,

You are reading the current chase camera position, but you aren't assigning back the modified position.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SuperScience · Sep 20, 2019 at 06:49 PM 0
Share

For the time being, I recommend removing all of the activestate stuff so that you can get the "happy path" working.

But essentially here's the main issue: you are reading out the value... ChaseCameraPos = ChaseCamera.transform.position; .. and then you modify it... ChaseCameraPos = new Vector3(h, 1.41f, -4.367f); .. but you never write back. (Actually in the 2nd line, you're overwriting the previous line).

I think that what you want to do is ChaseCamera.transform.position = new Vector3(h, 1.41f, -4.367f);

avatar image connoradams251 SuperScience · Sep 20, 2019 at 06:52 PM 0
Share

Thank you, I really don't know how I didn't think about it overwriting.

avatar image SuperScience · Sep 20, 2019 at 06:56 PM 0
Share

I'm not sure what your game does, but I think I would recommend using transform.Translate for most cases.

transform.Translate(Vector3.forward h Time.deltaTime);

or Vector3.up, left (whatever direction you want positively assigned to the horizontal axis).

avatar image connoradams251 SuperScience · Sep 20, 2019 at 07:01 PM 0
Share

I was going to use transform.Translate, but I'm pretty sure that isn't limited to just -1 to 1. The only reason I wrote that code like that was that I wanted bounds where the camera would stop.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

183 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Move camera when mouse is near the edges of the screen 1 Answer

Need help updating camera position to go above the player 2 Answers

Multiple Targets Camera 1 Answer

How to spawn objects on a restricted sphere surface relative to camera? 1 Answer

How to make camera move like it does in the scene viewport? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges