i thank you and apologize in advance for A. helping me and B. the long message
i have begun to make a basic program to get used to physics and camera mechanics in unity 3d but i everytime i just i get the error the x below represents algebra for whatever the mouse position is at when the error occurs
Screen position out of view frustum (screen pos x, x) (Camera rect 0 0 1100 525)
UnityEngine.SendMouseEvents:smile:oSendMouseEvents (int)
while scrolling through i did find another error:
Assertion failed on expression: ‘IsNormalized(dir)’
UnityEngine.SendMouseEvents:smile:oSendMouseEvents (int)
this tends to happen when my mouse leaves the screen in the game tab or when i jump, when i jump everything stops rendering and the camera is no longer moveable, but when reason 1 occurs it just freezes the movement of the camera and constantly replays the error message
i only have 3 scripts for my player character and these are:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
[Tooltip("The rotation acceleration, in degrees / second")]
[SerializeField] private Vector2 acceleration;
[Tooltip("A multiplier to the input. Describes the maximum speed in degree / second. To flip vertical rotation, set Y to a negative value")]
[SerializeField] private Vector2 Sensitivity;
[Tooltip("The period to wait until resetting the input value. set this as low as possible, without encountering stuttering")]
[SerializeField] private float inputLagPeriod;
[Tooltip("The maximum angle from the horizon the player can rotate in degrees")]
[SerializeField] private float maxVerticalAngleFromHorizon;
private Vector2 velocity;
private Vector2 rotation;
private Vector2 lastInputEvent;
private float inputLagTimer;
private float ClampVerticleAngle(float angle)
{
return Mathf.Clamp(angle, -maxVerticalAngleFromHorizon, maxVerticalAngleFromHorizon);
}
private Vector2 GetInput()
{
inputLagTimer += Time.deltaTime;
Vector2 input = new Vector2(
Input.GetAxis("Mouse X"),
Input.GetAxis("Mouse Y")
);
if((Mathf.Approximately(0, input.x) && Mathf.Approximately(0, input.y)) == false || inputLagTimer >= inputLagPeriod)
{
lastInputEvent = input;
inputLagTimer = 0;
}
return lastInputEvent;
}
// Update is called once per frame
private void Update()
{
Vector2 wantedVelocity = GetInput() * Sensitivity;
velocity = new Vector2(
Mathf.MoveTowards(velocity.x, wantedVelocity.x, acceleration.x * Time.deltaTime),
Mathf.MoveTowards(velocity.y, wantedVelocity.y, acceleration.y * Time.deltaTime));
rotation += velocity * Time.deltaTime;
rotation += wantedVelocity * Time.deltaTime;
transform.localEulerAngles = new Vector3(rotation.y, rotation.x, 0);
}
}
the one above is for the camera
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Rigidbody))]
public class JumpPhysics : MonoBehaviour
{
public Vector3 jump;
public float jumpForce = 2.0f;
public bool isGrounded;
Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
jump = new Vector3(0.0f, 2.0f, 0.0f);
}
void OnCollisionStay()
{
isGrounded = true;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
{
rb.AddForce(jump * jumpForce, ForceMode.Impulse);
isGrounded = false;
}
}
}
this one above here is for the jump code
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float speed = 10f; //Controls velocity multiplier
Rigidbody rb; //Tells script there is a rigidbody, we can use variable rb to reference it in further script
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>(); //rb equals the rigidbody on the player
}
// Update is called once per frame
void Update()
{
float xMove = Input.GetAxisRaw("Horizontal"); // d key changes value to 1, a key changes value to -1
float zMove = Input.GetAxisRaw("Vertical"); // w key changes value to 1, s key changes value to -1
rb.velocity = new Vector3(xMove, rb.velocity.y, zMove) * speed; // Creates velocity in direction of value equal to keypress (WASD). rb.velocity.y deals with falling + jumping by setting velocity to y.
}
}
im not entirely sure if this one above (the movement code) is really necessary but i have added it anyway, my player components are:
all of my objects in the heirchy is as shown below:
this below is my assets:
i believe that one way of fixing this is setting the cursor to the middle of the screen constantly but i am unsure of how to do that with code