- Home /
Flipping Error! Spritesheet and JS!
Well, I have a sprite sheet and it only contains all movement in the right only!
So, no left movements!!
I checked some answers and found that if I changed the scale to negative, it'll work also for the left!! It mirrors the sprite!
So, I checked it in the inspector, it works! Both for left and right direction!
But, when I implement the same technique in the script during play, it does nothing!!
The local Scale has no effect at all!!
The script is as follows!!
var walkSpeed : float = 1.5; //speed of standarad wlak!
var runSpeed : float = 2.0; //speed of run
var fallSpeed : float = 2.0; //speed of falling down
var walkJump : float = 6.2; //jump height from walk
var runJump : float = 9.0; //jump height from run
var crouchJump : float = 10.0; //jump height from crouch
var gravity : float = 20.0; //force applied on char
var startPos : float = 0.0; //location for start position
var moveDirection : int = 1; //direction player facing || 1 right, 0 left
private var velocity : Vector3 = Vector3.zero; //speed of player and direction
private var jumpEnable : boolean = false; //toggle for jump standard
private var runJumpEnable : boolean = false; //toggle for run jump
private var crouchJumpEnable : boolean = false; //toggle for crouch jump
function Update()
{
var aniPlay = GetComponent("aniSprite"); //set aniPlay to aniSprite
var controller : CharacterController = GetComponent(CharacterController); //set controller to CharacterController
if(controller.isGrounded)
{
jumpEnable = false; //reset jumps
runJumpEnable = false; //reset jumps
crouchJumpEnable = false; //reset jumps
velocity = Vector3(Input.GetAxis("Horizontal"),0,0);
if(Input.GetKeyDown("Horizontal")>0.1f)
{
transform.localScale = Vector3(Mathf.Abs(transform.localScale.x,transform.localScale.y,transform.localScale.z);
}
if(Input.GetKeyDown("Horizontal")<0.1f)
{
transform.localScale = Vector3(-transform.localScale.x,transform.localScale.y,transform.localScale.z);
}
if(velocity.x==0) //idle left
{
aniPlay.aniSprite(7,3,3,1,1,10); //animation call to spritesheet
}
if(velocity.x>0)
{
aniPlay.aniSprite(7,3,0,0,6,12);
aniPlay.aniSprite(7,3,0,1,4,12);
}
if(velocity.x<0)
{
aniPlay.aniSprite(7,3,0,0,6,12);
aniPlay.aniSprite(7,3,0,1,4,12);
}
}
velocity.y -= gravity * Time.deltaTime; //set gravitiy
controller.Move(velocity * Time.deltaTime);
}
So, am I doing anything wrong??
Please do help!! I can't just let the player work only on the right direction at all!!
Everytime I click play!!
The quads Z scale = 0, and X scale goes negative!
I only need to change the X scale to negative when left arrow is pressed! X scale positive when right arrow is pressed!!
Also, z scale should remain 0.5f at all time!!
y scale also fixed!
But, every time I click play Z scale goes to 0!
Is it because of using quad!!
Could you please direct me on this!!
Your answer
Follow this Question
Related Questions
Simple Status UI (scale the distance) 1 Answer
2D games; Javascript or C#? 1 Answer
2D Character Movement Issues 1 Answer
2d enemy ai 0 Answers
How expensive is scaling in 2D unity? Is it better to pre-scale? 1 Answer