
[ad_1]
I’m at present making a prototype for a school mission in Unity. The recreation is a 2.5D platformer, although I’ve included a script for the digital camera from a 2D platformer so the digital camera strikes forward of the participant. Unfortunately, as a result of my character solely faces left and proper and would not rotate, the digital camera would not transfer forward to the left, which can make it tough for the participant to see forward in the event that they return to the left. I’m undecided what or how I might deal with the problem in a script. These are the digital camera and participant controller scripts I’ve in the intervening time:
CameraController:
utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
public class CameraController : MonoBehaviour
{
[SerializeField] GameObject participant = null;
[SerializeField] [Range(0.1f, 3f)] float followAhead = 2f;
[SerializeField] [Range(0.1f, 3f)] float smoothing = 1f;
const float m_minY = 2f;
Vector3 targetPosition;
Vector3 cameraOffset;
void Start()
{
cameraOffset = rework.place - participant.rework.place;
}
non-public void Update()
{
targetPosition = (participant.rework.place + (participant.rework.ahead * followAhead)) + cameraOffset;
targetPosition.y = Mathf.Min(targetPosition.y, m_minY);
rework.place = Vector3.Lerp(rework.place, targetPosition, smoothing * Time.deltaTime);
}
}
PlayerController:
utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
public class PlayerController : MonoBehaviour
{
public Animator anim;
public float transferSpeed;
public float jumpForce;
public bool jumped;
public float gravityScale;
public float knockBackForce;
public float knockBackTime;
public float invincibilityLength;
non-public float jumpDelay;
non-public Vector3 moveDirection;
non-public float knockBackCounter;
non-public float invincibilityCounter;
non-public CharacterController controller;
void Start()
{
Cursor.seen = false;
controller = GetComponent<CharacterController>();
/*jumped = false;
if(jumpDelay <= 0)
{
jumpDelay = 5;
}*/
}
void Update()
{
if (knockBackCounter <= 0)
{
float transferHorizontal = Input.GetAxis("Horizontal");
moveDirection = new Vector3(transferHorizontal * transferSpeed, moveDirection.y);
if (transferHorizontal > 0)
{
rework.eulerAngles = new Vector3(0, 90);
}
else if (transferHorizontal < 0)
{
rework.eulerAngles = new Vector3(0, -100);
}
if (controller.isGrounded)
{
moveDirection.y = -1f;
if (Input.GetKey(KeyCode.KeypadPlus))
{
moveDirection.y = jumpForce;
jumped = true;
//StartCoroutine(SpamBlockco());
}
else if(!Input.GetKey(KeyCode.KeypadPlus))
{
jumped = false;
}
}
}
else
{
knockBackCounter -= Time.deltaTime;
}
moveDirection.y = moveDirection.y + (Physics.gravity.y * gravityScale * Time.deltaTime);
controller.Move(moveDirection * Time.deltaTime);
anim.SetBool("isGrounded", controller.isGrounded);
anim.SetFloat("Speed", Mathf.Abs(Input.GetAxis("Horizontal")));
}
public void Knockback(Vector3 course)
{
knockBackCounter = knockBackTime;
moveDirection = course * knockBackForce;
moveDirection.y = knockBackForce;
}
/*public IEnumerator SpamBlockco()
{
if (moveDirection.y == jumpForce)
{
yield return new WaitForSeconds(jumpDelay);
}
yield return null;
jumped = false;
}*/
}
There are two methods I’d like for it to work – both when the participant presses left/proper, the character immediately rotates within the desired course and transfer forwards, or the participant presses left/proper, the character turns, after which the participant has to press left/proper for the character to maneuver.
[ad_2]