I am making 2D shooter platformer game and I have my player flipping to mouse direction and weapon following mouse cursor. However, the shootpoint will not flip too and I dont know how to flip anything withou sprite . Can anyone help me with this one?
var delta = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
if (delta.x >= 0 && !facingRight) { // mouse is on right side of player
transform.localScale = new Vector3(1,1,1); // or activate look right some other way
facingRight = true;
} else if (delta.x < 0 && facingRight) { // mouse is on left side
transform.localScale = new Vector3(-1,1,1); // activate looking left
facingRight = false;
}
THIS IS IN MY PLAYERCONTROLLER SCRIPT
AND THIS IS IN MY SHOOT SCRIPT
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShootScript : MonoBehaviour
{
public float offset;
private GameObject player;
private SpriteRenderer spriteren;
public GameObject Bullet;
public Transform ShootPoint;
public Animator anim;
public float BulletSpeed;
public float FireRate;
float readyForNextShoot;
Make sure when posting code to use the code tags so it is formatted correctly.
Both scripts are essential doing the same thing. I would have it control the arm in the player script along with the flipping(so you are only calculating once) and have a gun or weapon script that controls the firing/attacking. One caveat is that when it’s flipped left with -1 scale it will invert the rotation, here is a snippet from a game I’m working on.
I am not flipping any spriterenderer’s, setting the scale.x to -1 already does that for me. I have no offset, I have the arm and the sprites facing right by default.
Your way doesnt flip the gun when it cross 90 or -90 angle and I still have to flip char. Do you have any advice how to solve this my little problem please? Thank you
Player Body Sprite - Has the Player script that controls the arm pivot rotation
Arm Pivot(Shoulder) - Empty game object that is what get rotated
Arm Sprite - Only the arm sprite
Gun Attach Point - Empty game object allows swapping weapons
Gun - Has the Gun script that controls firing and reloading.
When I set the scale.x to -1 on the Player root (the body sprite) it flips every child including positions. I only worry about the rotation input for the arm when the player is flipped as it also flips how it rotates. I also have the body, head, arms, legs and feet as separate sprites.
Not sure how your player is setup, I have this kind of setup for a few different projects and have had no issues.