How can i make it so that when i press c the camera will go into first person view?,How can i change my view to first person view when i click c?
I have made it so that the the camera follows the player and the default camera view is a bit behind the person but i would like to have it so when i press c it will switch where the camera is. It already follows the player and i just need it to switch views when i press c. Please help.,I want to be able to press c and the camera will go into first person view on the player. I have already scripted it so that it follows my player but i need it so that it goes into a certain view when i click c.
Answer by ppg · Aug 30, 2017 at 12:32 AM
CAMERA LOCATION are u working with C# OR JAVA SCRIPT?
A bit of scripts to show always helps to get the right help needed 2 IMPORTANT QUESTIONS
Q1. are you trying to switch between 2 cameras? Q 2. are you trying to use one camera to switch perspective from top down/above player to first person where the players head is ?
if Q1 u will need to reference the cameras in your scene and set active cam to the camera on players head for the first person view
if Q2 u will need to access the Vector-3 transform position of the (camera.main) to switch the transform from top down location to first person location
show some scripts to get more detailed feedback hope it helps goodluck
////////////////////////////// SOLUTION: To make life easier use 2 cameras there are also additional benefits to doing it this way you wont have to mess with the transforms of cameras like all things you can do it the easy way or the hard way.
i choose an effective way to do it so CREATE 2 CAMERAS if u already have your top down camera all you need is a extra camera for first person.
TIPS. YOU CAN COPY THE TRANSFORM FROM 1 OBJECT TO ANOTHER " PAST COMPONENTS VALUE"
1 parent your cameras to your player object you can see the cameras view in the inspector so make sure both cameras views are set the way you want them to be during run-time/play-mode.
so you should have first person cam looking out from head position of player and top-down cam should be above players head and back a bit also with rotation x set to something like 40 in the transform component.
2 after your cameras are set up in the desired location with the right views ie / cam 1 view top down / cam 2 view first person/ and they are parented to your player object drag the switch cam script onto your player object.
3 in your player object in the inspector you will see 2 slots for camera named appropriately on the switchcam component . drag your topdown cam into the topdowncam slot and drag your first person cam into the first person cam slot.
i wrote the script to work to work with C key press as requested ENJOY
using UnityEngine;
using System.Collections;
public class switchcam : MonoBehaviour {
//reff cam for topdown
public Camera topdowncam;
//reff cam for firstperson
public Camera firstperson;
//switch trigger for cameras stored as a bool
public bool switchcamera;
// Use this for initialization
void Start () {
// why am i here if am not being used? delete me for optimisations sake (void start not being used)
}
// Update is called once per frame
void Update () {
// switch cameras on GetkeyUp
if(Input.GetKeyUp(KeyCode.C)){
if(switchcamera){
switchcamera = false;
topdowncam.enabled = false;
firstperson.enabled = true;
}else{
switchcamera = true;
topdowncam.enabled = true;
firstperson.enabled = false;
}
}
}
}
Can you please send me a photo of what the script would look like?
Answer by Gamingersp · Aug 30, 2017 at 01:13 AM
Here is my script so far, i just need to change where the cameras view is when i press c.Oh yeah and i am using C# @ppg
not much to look at in the pic but i understand what you are trying to do i will post a solution shortly
Answer by Nathanaji01 · Aug 30, 2017 at 01:23 AM
Hi. I need to know this as well. :)
Think of parenting like a folder. Folder is parent contents inside folder are children.
EVERY OBJECT CAN BE A FOLDER meaning every object can be a parent. you can do it through code(SetParent) or in inspector.
simply drag the child objects into the object you want to be the parent.
child will be like a content you are dragging into a folder the parent object.
so to recap if you know how to add things into a folder on a computer then you already know how to parent objects. THE EXACT TER$$anonymous$$ IS CALLED A DRAG AND DROP.
remember you can have many files inside a folder also folders can have other folders inside them. when you have too many files inside a folder you might want to group them hence why you have folders in folders. so you can parent and group multiple objects together based on your needs.
Extra info... A CO$$anonymous$$$$anonymous$$ON PRACTICE - USE A E$$anonymous$$PTY GA$$anonymous$$E OBJECT AS PARENT OBJECT. because a empty game object don't come pre-loaded with game components you don't need just like on a computer when you create folders they would be empty for practical use.
IN SO$$anonymous$$E CASES IT IS I$$anonymous$$PRACTICAL TO USE A E$$anonymous$$PTY GA$$anonymous$$E OBJECT. because you need the parent object to have other game components you might need.
example when you create a unity folder to start a project even thou its a new folder it comes pre-loaded with what unity needs in developing your project ie..assembly,assets folder etc..
Are you new to unity? parenting objects are BASIC essentials with unity's work flow. make it a habit to use the Script-Reference in unity to search for exact terms you are unfamiliar with. good luck