Hello Volkz :),
first to know … i’m normally not speaking english (excuse me, it’s just RealTime)
i’m coming over from unreal engine (not really learned, but got some impressions) and i tried to move a camera like i can do there) (Worth to say, i’m a bloody beginner). i’ve got the forward vector (i think i do) and multiply it with a, let’s say, movement speed. The other vectors are handled equally.
It may be important that the project is nearly equal a blank project. I just added a Terrain, put some Cylinders on it, built a Navmesh and added “Ethan” (but only the .fbx not fully) to it (in confidence: just to see how the pathfinding works ;),thats why “Ethan” has an NavMeshAgent and a NavMeshObstacle (Deactivated) Component). (I wonder why i can import 200 meshes built out of MakeHuman with 28,796 faces (14,444 vertices) which take my framerate down to ~36 fps (cooked project) and only 40 “Ethans” which have (as i know (Blender v.2.78)) 7.443 faces (7.442 vertices) wich takes down my framerate to ~30 (cooked project also).
I just trying to test a little bit, (i’m amazed, first looks are like a candy in comparison to unreal engine).
But i didn’t get the camera moved with some strange behaviours in the Debug.Log. It’s just the “Main Camera” with a additional C# Script called CameraController.
If i pushing “w” (standard configuration) it shows me my Debug.Log as i expected… but if i’m pressing “a” it shows me two Debug.Log Messages (I assume the one from the “w” key is showed too).
i’ve just programmed some kind of C (i’ll say “nuts”-C because there wasn’t any difficulty) before, but i think something do go wrong.
Here is my code for the CameraController Script (and i will be very happy if you tell me how i put this in an extra “box” (the helpfully text on the right of this window won’t show me how) and ill do this (if i can (it’s my first post here) as soon as i know how).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour {
private Vector3 ForwardMovement;
private Vector3 RightMovement;
private Vector3 UpMovement;
private bool Debugging;
void Start () {
Debugging = true;
}
void Update () {
}
void LateUpdate () {
float moveVertical = Input.GetAxis ("Vertical");
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveUpDown = Input.GetAxis ("UpDown");
if (Debugging == true) {
Debug.Log ("Forward Vector: " + transform.forward);
Debug.Log ("Right Vector: " + transform.right);
Debug.Log ("Up Vector: " + transform.up);
}
if (moveVertical != 0.0f) {
Vector3 ForwardMovement = MultiplyVectorWithFloat (transform.forward, moveVertical * 5);
} else {
ForwardMovement = ClearVector (ForwardMovement);
}
if (moveHorizontal != 0.0f) {
Vector3 RightMovement = MultiplyVectorWithFloat (transform.right, moveHorizontal * 5);
} else {
RightMovement = ClearVector (RightMovement);
}
if (moveHorizontal != 0.0f) {
Vector3 UpMovement = MultiplyVectorWithFloat (transform.up, moveUpDown * 5);
} else {
UpMovement = ClearVector (UpMovement);
}
if (Debugging == true) {
Debug.Log ("Forward: " + ForwardMovement.ToString ());
Debug.Log ("Right: " + RightMovement.ToString ());
Debug.Log ("Up: " + UpMovement.ToString ());
}
Vector3 Movement = ForwardMovement + UpMovement + RightMovement;
transform.position = transform.position + Movement;
}
Vector3 AddFloatToVector( Vector3 Vector, float Float ) {
Vector3 Test = Vector;
Vector.x += Float;
Vector.y += Float;
Vector.z += Float;
if (Debugging == true) {
Debug.Log ("Added: " + Vector.ToString () + " with " + Float + " Original: " + Test.ToString ());
}
return Vector;
}
Vector3 MultiplyVectorWithFloat( Vector3 Vector, float Float ) {
Vector3 Test = Vector;
Vector.x *= Float;
Vector.y *= Float;
Vector.z *= Float;
if (Debugging == true) {
Debug.Log ("Multipied: " + Vector.ToString () + " with " + Float + " Original: " + Test.ToString ());
}
return Test;
}
Vector3 ClearVector(Vector3 Vector) {
Vector.x += 0.0f;
Vector.y += 0.0f;
Vector.z += 0.0f;
return Vector;
}
}