I am currently remaking a game that was a 2D college project, it is a 1945 clone. I have the movement controls sorted, now I am trying to rotate the player object left and right around 30 degrees, using a Quaternion.Lerp, so that it adds more of a feel to the horizontal movement.
I know a little C#, but apparently not enough as right now I am lost, I would really appreciate some guidance and some assistance. Thank you in advance!
here is the movement script, currently the only script in the game.
using UnityEngine;
using System.Collections;
public class MovementScript : MonoBehaviour {
public float speed = 300f;
public float xVelocity;
public float borderX = 15;
public float borderY = 10;
void Update()
{
Movement();
}
void Movement()
{
Vector3 pos = transform.position;
Quaternion rot = transform.rotation;
float moveHoriz = Input.GetAxis("Horizontal");
float moveVert = Input.GetAxis("Vertical");
xVelocity = rigidbody.velocity.x;
float horizCalc = moveHoriz * speed * Time.deltaTime;
float vertCalc = moveVert * speed * Time.deltaTime;
float rotationAmount = 30;
rigidbody.AddForce(horizCalc, 0, vertCalc);
pos.x = Mathf.Clamp(transform.position.x, -borderX, borderX);
pos.z = Mathf.Clamp(transform.position.z, -borderY, 0);
transform.position = pos;
transform.rotation = Quaternion.Lerp(Quaternion.Euler(Vector3(rot.x, rot.y, rot.z)), Quaternion.Euler(new Vector3(rot.x, rot.y,rot.z(rotationAmount * moveHoriz))), 1 * Time.deltaTime);
if(pos.x <-borderX + 0.1 || pos.x > borderX - 0.1)
{
//xVelocity = 0f;
if(moveHoriz <-0.1f)
xVelocity = -1f;
if(moveHoriz >0.1f)
xVelocity = 1f;
}
}
}