I’ve been lurking these forums for a good while now and normally I can find my answer of at least something close enough but sadly I can not for this issue.
So the concept we are using for movement is sorta like a “string” the player can moves their aiming reticule along X and Y. The player’s “Body” follows behind where every they aim but a slightly slower pace, The camera itself follows the player and has a smaller “movement box” and is confined to stay in it and will “tilt” with the player.
The issue I am having is that I assumed I could just have the player look at the aiming reticule and follow with a Lookat but the issue is while it moves great and does what I want (IE follows the aiming reticule fine and rotates towards it) it moves along X,Y fine but some reason it gets pushed back along Z, so it seems to get further and further away from the aiming reticule. Though while typing this I think I might have to program out the movement exactly instead of using Lookat.
The Scripting question I have is… I want to confine the player, aiming reticule, and camera in a “movement box” which I guess I mean by that is an area they are allowed to move in that isn’t dictated by the edges of the screen. my problem is I just don’t know how to go about stopping them from passing the edges of my box with allowing full movement. My example is if I move left to the edge of the box I want the player/Aiming reticule to no longer be allowed to move left anymore but still have full motion to go right, up, down. What seems to have caused me the most issue is trying to restrict the player controlled movement of the aiming reticule. I can get it to stop but it won’t let me move left/right anymore… Any help with this would be amazingly helpful I’ll include the code of what I have for the aiming reticule (though my if’s aren’t filled out)
using UnityEngine;
using System.Collections;
public class Aiming : MonoBehaviour
{
//movement
public float aimingSpeed;
public float movingFoward;
private float amtToMoveFoward;
//aiming box
private Vector3 aimingBoxLeft = new Vector3(-15,0,0);
private Vector3 aimingBoxRight = new Vector3(15,0,0);
private Vector3 aimingBoxUp = new Vector3(0,15,0);
private Vector3 aimingBoxDown = new Vector3(0,-1,0);
void Start ()
{
}
void Update ()
{
//movement method
AimingMovement();
}
void AimingMovement()
{
//movement
amtToMoveFoward = movingFoward * Time.deltaTime;
float amtToMove = Input.GetAxisRaw("Horizontal") * aimingSpeed * Time.deltaTime;
float amtToMoveUp = Input.GetAxisRaw("Vertical") * aimingSpeed * Time.deltaTime;
transform.Translate(Vector3.right * amtToMove);
transform.Translate(Vector3.up * amtToMoveUp);
transform.Translate(Vector3.forward * amtToMoveFoward);
//Box Check
if (transform.position.x < aimingBoxLeft)
{
}
if (transform.position.x > aimingBoxRight)
{
}
if (transform.position.y < aimingBoxDown)
{
}
if (transform.position.y > aimingBoxUp)
{
}
}
}