- Home /
Question by
OldManHighwind · Feb 12, 2021 at 01:31 AM ·
2d2d game2d-platformer2d-physicsprojectile
I need to shoot a projectile in my 2D platformer in the opposite direction my player is dashing which can be in any direction the player points the joystick
I've got to the point where if I dash I spawn in a bubble that doesn't move, my dash is calculated based on the raw axis for Horizontal and Vertical. I realise I need to get those variables and then apply force in the opposite of them which I can do by mulitplying them by -1. I know roughly what parts I need to do here but I can't seem to get this working right.
Here's my Bubble Projectile script:
private void Start()
{
StartCoroutine(DestroyBubble());
}
// Update is called once per frame
void Update()
{
}
IEnumerator DestroyBubble()
{
yield return new WaitForSeconds(timeToLive);
Destroy(gameObject);
}
And here's the references on the player script:
private void Update()
{
if (Input.GetButtonDown("Fire1") && !hasDashed && !wallGrab)
{
if (xRaw != 0 || yRaw != 0)
{
Dash(xRaw, yRaw);
BubbleFire();
}
}
}
Basically I need to be able to set the direction using the opposite direction of the xRaw and yRaw that's fed into the Dash Method and I have a seperate Bubble Fire Method that instantiates the Bubble Projectile.
Comment
Answer by DevManuel · Feb 17, 2021 at 08:26 AM
I'm not sure if I understood it correctly, but here is what I would do:
Dash(-1 * xRaw, -1 * yRaw);
Hope it helps.