- Home /
How to flip, on click a constant moving 2d rigidbody on the x-axis and maintain speed?
Hey all, I'm new to this coding scene and I dove in head first into my first game however off the bat I encountered an issue that I can't seem to resolve on my own. The idea of my game is to have the "player" be a constant moving object facing one direction and when you tap the screen: the sprite flips on the x-axis and continues the other way at the same speed awaiting for another tap to go the other way. I can't seem to find the correct lines of code to make this happen and so now I've become a frustrated beginner and want to quit this whole thing but thought I'd ask for help from the community . I will post the lines of code I have been throwing at it, to no avail. Thank you in advance for the help, this will be a learning experience for me. P.S If this type of question has been posted before I apologize I couldn't find it or didn't type in the correct search words.
{
void Start()
{
FacingRight = true;
Rb = GetComponent<Rigidbody2D>();
}
void Update()
{
Rb.velocity = new Vector3(Speed, 0, 0);
if (Input.GetMouseButtonDown(0))
{
Debug.Log("moo");
//FacingRight = !FacingRight;
Vector3 TheScale = transform.localScale;
TheScale.x = -8;
transform.localScale = TheScale;
Rb.velocity = new Vector3(-Speed, 0, 0);
}
if (Rb = transform.localScale (-8))
{
Rb.velocity = new Vector3(Speed, 0, 0);
}
{
// FacingRight =!FacingRight;
// Rb.velocity = new Vector3(-Speed, 0, 0);
//FacingRight =! FacingRight;
//Vector3 TheScale = transform.localScale;
//TheScale.x = 8;
//transform.localScale = TheScale;
}
}
}