How to get a Projectile to follow a Parabola

Yes thank you for all, i think i’ll give some shoot to all of this and then i’ll proceed with the next part of the 2d course! maybe i’ll stick for a bit with the pathing solution i got before, because even if it is not super elegant and precise, it’s still functional and i can get with it a lot of different paths!
:smiley:

Ok i know i said i would have tried this alone but i need a last final little hand, i tried to use the lookAt method but i didn’t manage to rotate the object only in the Z-axis, it kept changin all the object axis going outside the 2d field, i looked over the internet and i saw that for the anchoring of only 1 or 2 axis it is adviced to use a formula like this:

  private void Rotate(Vector3 targetPosition)
    {
        Vector3 difference = targetPosition - transform.position;
        float rotationZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
        transform.rotation = Quaternion.Euler(0, 0, rotationZ);

    }

it’s a math based formula and i understand it, it works but the problem is that unlike the lookAt method the movement is a little sloppy, how could i do an interpolation between the rotation in each point? i saw people using methods like Larp but it didn’t work


this is what happens using lookat

i tried to also give as parameters of the lookat a vector 3 with only the z rotation but it didn’t worked

just passing by to say that i solved this haahha i even implemented a lot of different new scripts, powerups, healt pick ups , animation and i managed to get some sort of loot system , (i simply put a random number generator inside every enemy and when i get to some range at runtime it set the enemy to drop a certain item, it works pretty well and i’m surprised because i thought of this all by myself ahah)
this is how i changed the code

 private void Rotate(Vector3 targetPosition)
    {
        Vector3 difference = targetPosition - transform.position;
        float rotationZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
       var quat= Quaternion.Euler(0f, 0f, rotationZ);
        transform.rotation = Quaternion.Lerp(transform.rotation, quat, Time.deltaTime * 5);
    } 
    

Great job! The video looks really fantastic. Did you use the path or did you write a script for the parabolic movement?


See also:

1 Like

Thank you! no it’s still the waypoint path

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms