So I started making my own 2.5 platformer and have run into quite a few problems.
I got many of the basic systems working, but a few things are giving me issues. I’m using rigidbody and the z-axis as forward. Since the player is supposed to go in both directions and turn to face the direction he’s walking towards.
The way I went about it is below (player script, called in fixed update):
//horizontal movement
rigidBC.velocity = new Vector3(rigidBC.velocity.x, rigidBC.velocity.y, horizontalImput*walkSpeed);
animator.SetFloat("speed", (FacingSide * rigidBC.velocity.z) / walkSpeed);
//facing by current rotation and horizontal imput
//0° on Y axis = postitive horizontal imput = right
//180° on Y axis = negative horizontal imput = left
if ((this.transform.rotation.y == 0) && (horizontalImput < 0))
{
Debug.Log("Moving right");
rigidBC.MoveRotation(Quaternion.Euler(new Vector3(0, 180, 0)));
}
if ((this.transform.rotation.y == 180) && (horizontalImput > 0))
{
Debug.Log("Moving left");
rigidBC.MoveRotation(Quaternion.Euler(new Vector3(0, -180, 0)));
}
the player starts looking right (0° rotation) and rotates properly when I move left, but then never rotates back. (at this point I want to integrate a button that locks the facing, so you can back up while shooting forward)
I tried using the same system inside my bullet script (so it fires in he direction the player is facing), but it doesn’t work at all there, bullets always go right (I don’t want to use mouse aiming, just regular old-school shoot straight forward)
public void Fire(Vector3 position, Vector3 euler, int layer)
{
lifeTimer = Time.time;
transform.position = position;
transform.eulerAngles = euler;
transform.position = new Vector3(0, transform.position.y, transform.position.z);
//transform.rotation = Quaternion.LookRotation(vop, Vector3.right);
transform.rotation = Quaternion.Euler(0f, 0f, 0f);
if (this.transform.rotation.y == 0)
{
Vector3 vop = Vector3.ProjectOnPlane(transform.right, Vector3.right);
transform.right = vop;
}
if (this.transform.rotation.y == 180)
{
Vector3 vop = Vector3.ProjectOnPlane(transform.right, Vector3.left);
transform.right = vop;
}
}
I feel like an idiot. What am I missing here?