Search Unity

Leading a child object in a rotating, moving parent

Discussion in 'Physics' started by imchrissharp, May 24, 2018.

  1. imchrissharp

    imchrissharp

    Joined:
    May 2, 2018
    Posts:
    15
    Hey everyone! I have a problem that I can't seem to pass.

    I have been able to successfully launch a projectile of a given speed at an object moving at a given velocity so they impact at a possible time t.

    My assumptions were as follows (where S is the velocity of the projectile.)

    upload_2018-5-23_20-52-45.png

    From here further simplification helped by reducing the two seperate Positions and Velocities to Deltas of the two. By squaring both sides I am able to give S a value and create a quadratic for t and solve from there.





    (Yay!)


    So this worked perfectly until I noticed that if I was firing at a child object of a parent that was rotating this would get funky. I made a noble attempt at this but I am ultimately confused, so I am looking for help with this part:

    I am shooting at a target which is a child of a parent object that "can" be rotating around the y axis (Think shooting at a point on an asteroid that's rotating on 3 axis... but just 1 axis here since its top down (y). If you can help me with 3 I would looooooove you). I want to lead this target so that as long as no angular acceleration or physical acceleration happens that every shot will hit its mark similar to above.

    I was able to get a "top down" view working but I am struggling hard with getting this to work in 3D space.

    upload_2018-5-23_21-5-1.png

    In this example I have a ship moving through space at a velocity and it's rotating about its central point. The box in the lower left is a child of the ship. The sphere at the top right is the projected location of the box in t=2 seconds.

    This is great, but I need t to be dynamic and be subject to the above concept.

    The equations I used for this initial angular thing were basically the same with a few small changes.

    1. The target's position is no longer considered. Instead of acquiring the square's position directly I get the position of the parent (the ship) and add the difference of the square and the parent.

    upload_2018-5-23_21-8-16.png

    I then use a circle equation to figure out what's going on (Where theta is the initial rotation of the child with respect to world coordinates) and solve individually for the xPos and zPos.




    I then take these individually and compare them to the shooter position/velocity like I did above. (Maybe this is where I'm going wrong? Or maybe that was a long time ago :p )




    Doing the deltas again here I get the following




    From here I have been spinning my wheels endlessly trying to figure out a workable solution for this. I am using the eulerAngle.y for the omega which works well. Ultimately I just need that instantaneous point in space that I should fire at which is a product of the speed of the bullet and the distance of the projection, and then my turrets aiming scripts will take care of the rest.

    Any help would be so appreciated, I can't sleep until I figure this out D:

    Chris
     

    Attached Files: