- Home /
Question by
Timze · May 22, 2017 at 03:13 PM ·
2dinstantiateprefabrigidbody2dshoot
When flipping player, instantiated objects spawn on different spot. 2D shooting
Hey, I followed tutorial at https://www.youtube.com/watch?v=SlEFoM4h3Mc&t. As couple guys already mentioned on latest comments: When shooting the other way (flipping the sprite on x-axis) the projectile shoots from a bit different spot. (from feet)
{
public GameObject projectile;
public Vector2 offset = new Vector2(1f, 1f);
public Vector2 velocity;
float cooldown = 1;
bool canThrow = true;
void Update()
{
if (Input.GetKeyDown(KeyCode.E) && canThrow)
{
GameObject clone = (GameObject)Instantiate(projectile, (Vector2)transform.position + (offset * transform.localScale.x), Quaternion.identity);
clone.GetComponent<Rigidbody2D>().velocity = new Vector2(velocity.x * transform.localScale.x, velocity.y);
StartCoroutine("CanThrow");
}
}
IEnumerator CanThrow()
{
canThrow = false;
yield return new WaitForSeconds(cooldown);
canThrow = true;
}
}
Any ideas here for a fix? :) Tested on 5.6 and 5.6 beta. Thanks already in advance.
Comment
Still no any ideas for this? :(
I made a test scene in case someone got time to check it out. Simple small test scene. Download link: https://ufile.io/7pg7l
Thanks in advance.