Hello! Thanks in advance for the help and my apologies for a probably pretty newbie question but been struggling to figure this out properly. I’ve been learning how to make character controllers for a platformer and it’s been going good but I am a much better artist and animator than a programmer. Need some help adapting the movement script to use GetComponent<Puppet2D_GlobalControl>().flip = true;
as my character flipping method.
I am using a skeletal animation solution called Puppet2d and in order for flipping assets to work properly I must use that component I mentioned above, otherwise the bone positioning gets screwed up.
Here’s my script below before I add the component to it.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class spacemancontroller : MonoBehaviour {
//how fast the character can move
public float topSpeed = 10f;
// tell the sprite which way it is facing
bool facingRight = true;
//physics in fixed update
void FixedUpdate()
{
//get move direction
float move = Input.GetAxis ("Horizontal");
//add velocity to the rigidbody in the move direction * our speed
GetComponent<Rigidbody2D>().velocity = new Vector2(move * topSpeed, GetComponent<Rigidbody2D>().velocity.y);
//if were facing the neg direction and not right, flip
if (move > 0 && !facingRight)
Flip();
else if (move < 0 && facingRight)
Flip();
}
void Flip()
{
//saying we are facing the opposite directions
facingRight = !facingRight;
//get the local scale
Vector3 theScale = transform.localScale;
//flip on the x axis
theScale.x *= -1;
//reapply that to the level scale
transform.localScale = theScale;
}
}
I’ve been reading over the script trying to make sure I understand exactly what’s happening at each line but I think I’m misunderstanding part of it because when I replace the instances of Flip();
with GetComponent<Puppet2D_GlobalControl>().flip = true;
I can get the character to properly turn around once but I can’t get him to turn around again.
Thanks again for any help you guys can provide, I’ve been sitting on this for many days without any luck.