Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C#-Quelltext |
|
1 |
transform.Translate(0, 0, 0.03f); |
C#-Quelltext |
|
1 |
transform.Rotate(-0.8f, 0, 0); |
Quelle: Unity Script ReferenceZitat
If relativeTo is left out or set to Space.Self the movement is applied relative to the transform's local axes. (the x, y and z axes shown when selecting the object inside the Scene View.) If relativeTo is Space.World the movement is applied relative to the world coordinate system.
C#-Quelltext |
|
1 |
transform.Translate(0, 0, 0.03f, Space.World); |
C#-Quelltext |
|
1 |
transform.Rotate(0, -0.8f, 0, Space.World); |
Ich weiß schon, dachte nur ich könnte es vielleicht auch bei "Rotate" benutzen, da hat es aber keine WirkungAlso ich weiß jetzt nicht genau, was dann passiert, wenn man das bei rotate dazusetzt, aber ich hatte in meinem Post nur von translate geredet!
Mfg Harry222
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
using UnityEngine; using System.Collections; public class CameraMove : MonoBehaviour { //TODO: there arent any borders which stops zu from scrolling of the map //some public stuff public float movingSpeed = 5.0f; public float scrollingSpeed = 5.0f; public float rotationSpeed = 5.0f; public float maxScrollingHeight = 50.0f; public float minScrollingHeight = 50.0f; public bool showMouse = true; //Directions private Vector3 forward = Vector3.forward; private Vector3 back = Vector3.back; private Vector3 left = Vector3.left; private Vector3 right = Vector3.right; //For rotating around private RaycastHit hit; private Ray ray; //"Map" private LayerMask layerMask = 1 << 8; // Use this for initialization void Start () { if(showMouse) { Screen.showCursor = true; } else { Screen.showCursor = false; } } // Update is called once per frame void Update () { //Checking for Window Scrolling WindowScrolling(Input.mousePosition,movingSpeed,Input.GetAxis("Horizontal"),Input.GetAxis("Vertical")); //Scrolling in and out MouseWheelScrolling(Input.GetAxis("Mouse ScrollWheel"), scrollingSpeed); //Rotate the Camera MouseRotation(Input.GetKey(KeyCode.Mouse2), rotationSpeed); } void WindowScrolling(Vector3 mousePos, float speed, float horizontalAxis, float verticalAxis) { //width if(mousePos.x <= 0.0f || horizontalAxis < -0.2f) { Scrolling(left, speed); } else if(mousePos.x >= Screen.width || horizontalAxis > 0.2f) { Scrolling(right, speed); } //height if(mousePos.y <= 0.0f || verticalAxis < -0.2f) { Scrolling(back, speed); } else if(mousePos.y >= Screen.height || verticalAxis > 0.2f) { Scrolling(forward, speed); } } void MouseWheelScrolling(float scrolling, float speed) { //up if(transform.position.y < maxScrollingHeight && scrolling < 0.0f) { Scrolling(Vector3.up, scrollingSpeed); } //down else if(transform.position.y > minScrollingHeight && scrolling > 0.0f) { Scrolling(Vector3.down, speed); } } void MouseRotation(bool isKeyDown, float speed) { if(isKeyDown) { ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width * 0.5f, Screen.height * 0.5f, 0.0f)); //if mouseposition < the middle of the screen rotate left and > rotate right float tempSpeed = Screen.width * 0.5f - Input.mousePosition.x; //adjustment and speed multiplikation tempSpeed *= speed * Time.deltaTime * 0.1f; //sending a ray to the map... //ps: wtf,why does the layermask not work? if(Physics.Raycast(ray,out hit,Mathf.Infinity,layerMask)) { //...and rotating around transform.RotateAround(hit.point,Vector3.up,tempSpeed); //calculate the new directions for moving the camera NewDirectionsUntilRotation(hit.point); } } } //----------------------- //Helpfunctions //----------------------- //For moving and scrolling in a direction with a speed void Scrolling(Vector3 direction, float speed) { transform.position += direction * speed * Time.deltaTime; } //To calculate the new directions after rotating the Camera void NewDirectionsUntilRotation(Vector3 rotationPoint) { //x---z x is the camera position, y is the hit of the ray //-\--| and z is our new position to calculate the directions //--\-| norm(z-x) is the new forward //---\| //----y Vector3 upperMiddlePos = new Vector3(rotationPoint.x,transform.position.y,rotationPoint.z); forward = upperMiddlePos - transform.position; forward.Normalize(); back = -forward; left = transform.TransformDirection(Vector3.left); right = transform.TransformDirection(Vector3.right); } } |
Naja, ist das nicht etwas sehr umständlich, wenn ich die Veränderung jeweils speichern muss und es dann "zurückändern" muss.Neu berechnen bedeutet, das du den Up-Vektor für das lokale Koordinatensystem im Weltkoordinatensystem haben möchtest?
Speicher dir am besten den Up-Vektor und verändere ihn jedes mal wenn du rotierst mit TransformDirection
PS: Warum ohne Beachtung der aktuellen Werte?
Werbeanzeige