Quantcast
Channel: Questions in topic: "controlled"
Viewing all articles
Browse latest Browse all 8

Controlled Camera Movements

$
0
0
Hey guys, I am trying to work a camera view to move like the following diagram: 0<-^-> If the "0" is the player, I would like the camera (behind the player) to be able to move freely in a 260 degree manner, rather than 360 degrees. The end goal I am looking for is to not to be able to move the camera behind the player on screen, which my current code is doing. I used this code from others as well as modified it a little bit, received help, etc.>>**Here is the code I have so far:** using UnityEngine; using System.Collections; public class CameraControlScript : MonoBehaviour { public float sensitivityX = 8F; public float sensitivityY = 8F; float mHdg = 0F; float mPitch = 0F; void Start() { } void Update() { if (!(Input.GetMouseButton(1))) return; float deltaX = Input.GetAxis("Mouse X") * sensitivityX; float deltaY = Input.GetAxis("Mouse Y") * sensitivityY; if (Input.GetMouseButton(1)) { ChangeHeading(deltaX); ChangePitch(-deltaY); } } void MoveForwards(float aVal) { Vector3 fwd = transform.forward; fwd.y = 0; fwd.Normalize(); transform.position += aVal * fwd; } void Strafe(float aVal) { transform.position += aVal * transform.right; } void ChangeHeight(float aVal) { transform.position += aVal * Vector3.up; } void ChangeHeading(float aVal) { mHdg += aVal; WrapAngle(ref mHdg); transform.localEulerAngles = new Vector3(mPitch, mHdg, 0); } void ChangePitch(float aVal) { mPitch += aVal; WrapAngle(ref mPitch); transform.localEulerAngles = new Vector3(mPitch, mHdg, 0); } public static void WrapAngle(ref float angle) { if (angle < -360f) angle += 360f; if (angle > 360f) angle -= 360f; } }> Any tips on how I can achieve this, or keywords I may be able to search for and begin the process of figuring it out. Thanks for taking the time to read and help out.>Am I even on the right track?>I will clarify more if need be.

Viewing all articles
Browse latest Browse all 8

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>