DoomPriestK
Active Coder
[CODE lang="csharp" title="Raycast Shot"] RaycastHit2D hitInfo = Physics2D.Raycast(BulletShootPoint.position, BulletShootPoint.right);
if(hitInfo)
{
Debug.Log(hitInfo.transform.name);
}[/CODE]
Hi all, my Raycast always shoots to the right, even when the character is facing left, i've tried different ways of getting the characters current position and replacing BulletShootPoint.right but nothing seems to work...
I have other code alsewhere that stops all the child objects of the player from flipping with him but even if I disable that code the Raycast always shoots right, I tried Raycast.forward, replacing BulletShootPoint.right with theRB.localScale.x but that didn't seem to fix it either, the Raycast stopped shooting altogether
[CODE lang="csharp" title="Stop Children Flipping"] // IF THE LEFT DIRECTION IS USED
if (theRB.velocity.x < 0)
{
// TURN SPRITE TO FACE LEFT
transform.localScale = new Vector3(-1, 1, 1);
// STOP THROWPOINT TURNING WITH IT (Otherwise projectiles turn too)
foreach (Transform child in transform)
{
Vector3 childScale = transform.localScale;
childScale.x = -1;
child.localScale = childScale;
}
}
// ELSE IF THE RIGHT DIRECTION IS BEING USED
else if (theRB.velocity.x > 0)
{
// TURN SPRITE TO FACE RIGHT
transform.localScale = new Vector3(1, 1, 1);
// STOP THROWPOINT TURNING WITH IT (Otherwise projectiles turn too)
foreach (Transform child in transform)
{
Vector3 childScale = transform.localScale;
childScale.x = 1;
child.localScale = childScale;
}
}[/CODE]
Can someone help me out with where im going wrong?
Thanks!
if(hitInfo)
{
Debug.Log(hitInfo.transform.name);
}[/CODE]
Hi all, my Raycast always shoots to the right, even when the character is facing left, i've tried different ways of getting the characters current position and replacing BulletShootPoint.right but nothing seems to work...
I have other code alsewhere that stops all the child objects of the player from flipping with him but even if I disable that code the Raycast always shoots right, I tried Raycast.forward, replacing BulletShootPoint.right with theRB.localScale.x but that didn't seem to fix it either, the Raycast stopped shooting altogether
[CODE lang="csharp" title="Stop Children Flipping"] // IF THE LEFT DIRECTION IS USED
if (theRB.velocity.x < 0)
{
// TURN SPRITE TO FACE LEFT
transform.localScale = new Vector3(-1, 1, 1);
// STOP THROWPOINT TURNING WITH IT (Otherwise projectiles turn too)
foreach (Transform child in transform)
{
Vector3 childScale = transform.localScale;
childScale.x = -1;
child.localScale = childScale;
}
}
// ELSE IF THE RIGHT DIRECTION IS BEING USED
else if (theRB.velocity.x > 0)
{
// TURN SPRITE TO FACE RIGHT
transform.localScale = new Vector3(1, 1, 1);
// STOP THROWPOINT TURNING WITH IT (Otherwise projectiles turn too)
foreach (Transform child in transform)
{
Vector3 childScale = transform.localScale;
childScale.x = 1;
child.localScale = childScale;
}
}[/CODE]
Can someone help me out with where im going wrong?
Thanks!