- Home /
2D Platformer – changing the cursor position when facing left or right
Hi everyone, i’m having a trouble with shooting part. In general, i put my own character to game, and made him facing right when he go right and vice versa, facing left when he go left.
However the problem is that the gun in his hand is also changing the position, but the trail of shooting is not. And my question is, if anyone have some ideas how can i change (mirror) the trail of cursor when i change the position. If it is a little confusing i will show you my problem on photos:
Shooting when facing right:
Shooting when facing left:
Here is a code for rotating(fliping) an character, it's a part of PlatformerCharacter2D class:
// Move the character
rigidbody2D.velocity = new Vector2(move*maxSpeed, rigidbody2D.velocity.y);
// If the input is moving the player right and the player is facing left...
if (move > 0 && !facingRight)
// ... flip the player.
Flip();
// Otherwise if the input is moving the player left and the player is facing right...
else if (move < 0 && facingRight)
// ... flip the player.
Flip();
}
And here is a part of a code of shooting, drawing a trail, from Weapon script:
void Shoot () {
Vector2 mousePosition = new Vector2 (Camera.main.ScreenToWorldPoint (Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y);
Vector2 firePointPosition = new Vector2 (firePoint.position.x, firePoint.position.y);
So, if anyone could help me with this. I'm just begginer programmer, and also this is a part from tutorial, in which the guy didn't try to make this kind of mirroring. Also i write about my problem on brackeys forum, http://forum.brackeys.com/thread/2d-platformer-changing-the-cursor-position-when-facing-left-or-right/
Anyway, i would appreciate any help.
Your answer
Follow this Question
Related Questions
Help rotating gun towards mouse position (with flipping) 1 Answer
How do I get character dialogue to pop up? 2 Answers
Help with a game! 1 Answer
Player Flipping and Shot/Tilemap bugs 0 Answers