Hit Me - Animated & Ballistic Projectiles

Shoot your objects with ballistics or animate them. All with just one line of code or a Visual Scripting node.

Asset Store | Manual

https://vimeo.com/853694363

“Hit Me” is a projectile system with two modes of movement:
A) Animation (full control)
B) Ballistics (shoot like a cannon)

Easy to use
No coding skills required. Simply add a component and you are ready to go.

Animation
Tell the projectile what to hit and how long it should take. And while you are at it add some curves to make the flight path more interesting. Your target is moving? No problem. All curves will strecht accordingly.
You will have full control. No physics will skrew up your movement. Though you can set it to instantly enable physics if a collider is hit.

Ballistics
Shoot like a cannon. Let the projectiles be controlled by the physics engine (2D or 3D).

  • Prediction System: Let the code calculate where the target will be in the future and shoot there. It can even predict player motion (if not too chaotic).
  • Flight path visualization: Render the path (or the predicted path) with a LineRenderer.

  • Various calculation methods:
  • By Time: Choose how long the projectile will fly.
  • By Altitude: Choose how high the projectile will fly.
  • By Speed: Choose how fast the projectile will be.
  • By Angle: Choose the starting angle.
  • By Energy: Autmatically chooses the optimal angle.

[Experimental Feature] Conteracts Unitys physics simulation divergence*. Accurate to 0.2 units at a range of 1000 units. No need to increase the fixed delta time to hit your target!

Visual Scripting
Supports visuals scripting (formerly known as BOLT).

Lots of examples & documentation
Check out Kamgam/HitMe/Examples.

:heavy_check_mark: Full Source Code
I publish this asset with full source code because as a developer I know how annoying it is to not have source code access. If you like it then please remind others to purchase the plugin. Don’t just copy and paste it everywhere. Thank you :heart:

:heavy_check_mark: Supports Unity 2021.2+, 2022, 2023, 2024, … LTS
It may work with earlier versions too but those are not tested anymore.


Code Sample:

public class BallisticSimpleDemo3D : MonoBehaviour
{
    public Transform Source;
    public Transform Target;
    public GameObject ProjectilePrefab;
    public BallisticProjectileConfig Config;
    public void Start()
    {
        BallisticProjectile.Spawn(ProjectilePrefab, Source, Target, Config);
    }
}

Hope you like it.

Asset Store | Manual

1 Like

Hi geo_,

Firstly, I would like to extend my appreciation for developing the ‘Hit Me Animated Projectiles & Ballistics System’ asset. It has been a fantastic addition to my project. However, I have encountered a challenge while attempting to customize the trajectory of a 155 mm projectile.

In my scenario, the launch point is positioned at coordinates (0,0,0) with a target situated 10 km away at coordinates (10000, 0, 0). I am aiming to simulate an upside-down parabolic trajectory with an apogee altitude of 3000 m. However, with the current configuration, the projectile takes over 30 seconds to reach the target, which is significantly longer than my desired impact time.

I am seeking to adjust or override the existing configuration to achieve a total flight duration of 5 or 10 seconds while maintaining the specified 3000 m altitude apogee. I understand that this scenario might not align with real-world physics, but the objective is to create a specific simulation experience for my application.

I would appreciate any guidance on how I can modify the settings or the configuration to meet these requirements. Your expertise and assistance in this matter would be invaluable.

Thank you for your time and consideration. I am looking forward to your positive response.

Warm regards,
henryqng

1 Like

Hi, thank you for your kind words.

You won’t be able to do this with the ballistics since they are bound to physics (they are simulated by the Unity physics engine).

The way to go would be to use an animation instead. You can set an animation on the y-axis with a curve (parabola) and then scale that up to 3000 units (assuming you have a relation of 1 unit = 1 meter in your level).

It would look like this:

9403253--1316321--upload_2023-10-11_17-8-15.png

I have just given it a try in the “AnimationSimpleDemo3D” and it worked. However, please notice that this is no longer a physics driven shot but an animation.

Hope that helps :slight_smile:

1 Like

Thank you immensely for your prompt and insightful response. Your suggested approach of utilizing the animation system was spot-on and seamlessly catered to my requirements. I wish I had reached out to you earlier; it would have saved me a few hours of endeavoring to align the ballistic system with my scenario.

Your elucidation has broadened my understanding, providing me with two viable alternatives based on the desired simulation mode. For a real-world physics simulation, the ballistic system is the apt choice, whereas for a more game-centric (and perhaps unrealistic) mode, the animation system is ideal.

I am exceedingly content with your asset and the support provided. It’s not just the asset, but the knowledge and assistance accompanying it that adds significant value. Looking forward to exploring more functionalities and perhaps reaching out for guidance again.

Thank you once again for your invaluable support.

1 Like

Assistance Required: Integrating Custom Spin Script with AnimationProjectileSource in ‘Hit Me’ Asset.

Firstly, I’d like to express my gratitude for creating the ‘Hit Me - Animated & Ballistic Projectiles’ asset; it has significantly contributed to my project. I’ve successfully utilized the AnimationProjectileSource script to spawn projectiles in my scene. However, I encountered a challenge when attempting to implement a spinning effect on a 155 mm projectile using a custom script I developed.

Below is the script ProjectileSpin which I crafted to spin the projectile:

using UnityEngine;
using DG.Tweening;

public class ProjectileSpin : MonoBehaviour
{
    public float spinSpeed = 360f;  // Degrees per second

    void Start()
    {
        SpinProjectile();
    }

    /// <summary>
    /// Spin the 155 mm Projectile
    /// </summary>
    void SpinProjectile()
    {
        // Calculate the end rotation
        Vector3 endRotation = transform.eulerAngles + new Vector3(0, 0, spinSpeed);

        // Adjusted to turn clockwise
        endRotation *= -1;

        // Set up the rotation tween
        transform.DORotate(endRotation, 1, RotateMode.FastBeyond360)
            .SetEase(Ease.Linear)
            .SetLoops(-1, LoopType.Incremental);  // Infinite loops, incremental to keep spinning
    }
}

The script operates flawlessly, spinning the projectile when it is directly added to the scene. However, when integrated with the AnimationProjectileSource script to spawn the projectile, the spinning effect ceases to function.

I kindly seek your expertise on how I can resolve this issue to have the projectile spin while being animated by the AnimationProjectileSource script. Any guidance or suggestions would be highly appreciated.

Thank you in advance for your time and assistance.

Hi

Yes, this is to be exepcted. Though I understand that at first it’s a bit puzzling.

Let me explain:

This happens if you have chosen an alignment setting in the source (more details on alignments are in the manual).
9410033--1317671--upload_2023-10-15_9-47-59.png

If an alignment setting is used then an Alignment component will be added to each projectile. This component controls the ROTATION of the projectile and herein lies the problem. The Alignment and your ProjectileSpin will both try to change the rotation of the projectile in Update().

9410033--1317683--upload_2023-10-15_9-52-40.png

Now the particle`s rotation is in a pickle as it does not (and can not) know who is actually in charge of the rotation. DoTween or the Alignment component? Actually who wins depends on who is called last in the Update() cycle. You could configure DoTween to apply the changes in LateUpdate but then you would lose the alignment.

I have anticipated this problem and that’s what the “Apply” checkbox is for. If disabled then the Alignment component will calculate the rotation values but does NOT apply them. This enables you to fetch that rotation info and combine it with whatever other rotation you want to make (i.e. DOTween). This would require you to do some coding (read the alignment rotation, read the DoTween rotation, combine them, apply them).

However, there are some other solutions:

A) One thing you could try is to set the alignment in the projectile source to “none”. If you do that then it will not add the alignment component.
9410033--1317677--upload_2023-10-15_9-49-56.png
Though then the projectile will not align with the animation curve anymore. That’s probably not what you want.

B) You could wrap your whole projectile in another game object and use your ProjectileSpin component on the INNER game object.

Old Setup (conflicting components, no good):
9410033--1317686--upload_2023-10-15_10-3-16.png

New setup (no conflict, spinner INSIDE the projectile):
9410033--1317689--upload_2023-10-15_10-3-37.png

And last but not least instead of “transform.DORotate”, which does a GLOBAL rotation, you should use “transform.DOLocalRotate” which does a local rotation (also don’t forget to use local euler angles too):

using UnityEngine;
using DG.Tweening;

public class ProjectileSpin : MonoBehaviour
{
    public float spinSpeed = 360f;  // Degrees per second

    void Start()
    {
        SpinProjectile();
    }

    /// <summary>
    /// Spin the 155 mm Projectile
    /// </summary>
    void SpinProjectile()
    {
        // Calculate the end rotation
        Vector3 endRotation = transform.localEulerAngles + new Vector3(0, 0, spinSpeed);

        // Adjusted to turn clockwise
        endRotation *= -1;

        // Set up the rotation tween
        transform.DOLocalRotate(endRotation, 1, RotateMode.FastBeyond360)
            .SetEase(Ease.Linear)
            .SetLoops(-1, LoopType.Incremental);  // Infinite loops, incremental to keep spinning
    }
}

Result (in my test):

Hope this helps :slight_smile:

1 Like

Thank you for your prompt and thorough response. I am truly appreciative of the various solutions you provided.

Among the solutions, I found wrapping the entire projectile within another game object to be the most straightforward for my current scenario, and have successfully implemented it. This approach resolved the spinning issue seamlessly, and I am now able to achieve the desired projectile behavior in my project. BTW, your local transformation DOTween code worked perfectly! Thanks for going above and beyond to help me.

While the suggestion to disable the ‘Apply’ checkbox and fetch the rotations intrigued me due to the level of control it offers, I recognized that it would require a more advanced coding endeavor. I am keen on exploring this option in the future as I continue to enhance my skills.

I am immensely grateful for your assistance and am impressed by the exemplary support you’ve provided. Your asset has significantly enriched my project, and the service accompanying it is truly top-notch. I extend my heartfelt gratitude and wish you continued success in all your endeavors.

Thank you once again for your invaluable support.

Warmest regards!

1 Like

I take it it is not possible to make a prediction system for the animation mode, right?

Hi, I am not sure I understand what you want to achieve but the prediction system works for all modes. All it does is predict the position of the target at the time of arrival of the projectile and this info is then used as the target pos of the projectile animation or ballistic simulation.

What exactly is it that you want the projectile to do?

I want to use path drawing for the trajectory prediction in animation mode.

You should be able to do that with AnimationProjectile.DrawPath(…) even with prediction turned on as it will modify the target accordingly. There is a short section on that in the manual: https://kamgam.com/unity/HitMeManual.pdf#page7
Iirc one of the demo scenes has path drawing too.

If that is not working then please let me know.

1 Like