[Help] I have a problem with an asset

Hello and first of all thank you for reading :slight_smile:

I decided to launch myself on the development of a little game in 3D despite in a beginner.
I want to build a little soccer game. At this moment, I’ve build the pitch, and everything needed to play (ball … etc…) But now I have to make the game playable, and I don’t really know how to do it. I watched tutos on YT and tried to learn a bit more on C#. To help me through this big work, I bought an asset to calculate trajectory of the ball, but I don’t understand a word of the asset. I thought it would have be easy to use with the ReadMe of the asset but it wasn’t. The asset is this one : Unity Asset Store - The Best Assets for Game Making
I do everything told in the explanation doc, nothing happens. I tried to contact the creator by Email, now 4 months later he didn’t answer. I’m blocked on the project at this moment. Is it possible that someone help me by sending me to an appropriate tuto of how I can try to make this work, or everything linked on this subject of trajectory projectile. Thank you very much for your help, and sorry for my bad english.
Have a nice day !

Creating a game is not “easy”, especially if you don’t know what you’re doing. Simply buying an asset isn’t going to magically make a great game. As one of the asset’s reviews states, “As you can probably tell from above, you will need to know how to script to make use of this package, but it will deal with the complex single physics algorithm for you.”. Therefore, you should learn how to script in C# before you try to do something that complicated.

I’ve used this script before to achieve pretty much the same thing:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CatapultController : MonoBehaviour {
    public Transform CatapultArm;
    public float StartZRotation;
    public float EndZRotation;
    public float RotateSpeed;
    public bool Flinging;
    public bool Retracting;
    public float AccelerationMultiplier;
    public float AccelerationToAddPerFrame;

    public GameObject CurrentProjectile;
    public Transform ProjectilePositionDuringLaunch;
    public Rigidbody CurrentProjectileRigidbody;
    public Transform CurrentTarget;
    public float LaunchAngle;
    public bool LaunchedBall;
    // Use this for initialization
    void Start ()
    {
        CurrentProjectileRigidbody = CurrentProjectile.GetComponent<Rigidbody>();
        SetupRotation();
    }

    //NOTE: CREDIT TO Iron-Warrior from the Unity Forums: https://forum.unity3d.com/threads/how-to-calculate-force-needed-to-jump-towards-target-point.372288/
    void LaunchObject()
    {
        Vector3 p = CurrentTarget.position;
        float gravity = Physics.gravity.magnitude;
        // Selected angle in radians
        float angle = LaunchAngle * Mathf.Deg2Rad;
        // Positions of this object and the target on the same plane
        Vector3 planarTarget = new Vector3(p.x, 0, p.z);
        Vector3 planarPostion = new Vector3(CurrentProjectile.transform.position.x, 0, CurrentProjectile.transform.position.z);
        // Planar distance between objects
        float distance = Vector3.Distance(planarTarget, planarPostion);
        // Distance along the y axis between objects
        float yOffset = CurrentProjectile.transform.position.y - p.y;
        float initialVelocity = (1 / Mathf.Cos(angle)) * Mathf.Sqrt((0.5f * gravity * Mathf.Pow(distance, 2)) / (distance * Mathf.Tan(angle) + yOffset));
        Vector3 velocity = new Vector3(0, initialVelocity * Mathf.Sin(angle), initialVelocity * Mathf.Cos(angle));
        // Rotate our velocity to match the direction between the two objects
        float angleBetweenObjects = Vector3.Angle(Vector3.forward, planarTarget - planarPostion);
        Vector3 finalVelocity = Quaternion.AngleAxis(angleBetweenObjects, Vector3.up) * velocity;
        // Fire!
        CurrentProjectileRigidbody.velocity = finalVelocity;
        Debug.Log("Ball launched!");
        // Alternative way:
        // rigid.AddForce(finalVelocity * rigid.mass, ForceMode.Impulse);
    }

    void LateUpdate()
    {
        if (!LaunchedBall) //keep ball in position until launch
        {
            CurrentProjectile.transform.position = ProjectilePositionDuringLaunch.position;
        }
    }

    void FixedUpdate ()
    {
        if (Flinging)
        {
            if (CatapultArm.eulerAngles.z > EndZRotation && CatapultArm.eulerAngles.z <=StartZRotation)
            {
                //since Unity's physics with fast small objects is BS, this stops the ball from going thru the arm while swinging
                //if (Flinging)
                    //CurrentProjectile.transform.position = ProjectilePositionDuringLaunch.position;
                //smaller number means ball will launch later
                if (CatapultArm.eulerAngles.z - EndZRotation < 10 && !LaunchedBall)
                {
                    //launch ball to simulate real physics and prevent Unity's BS rigidbodies going thru each other
                    LaunchObject();
                    LaunchedBall = true;
                }
                AccelerationMultiplier *= AccelerationToAddPerFrame;
                CatapultArm.eulerAngles = new Vector3(CatapultArm.eulerAngles.x, CatapultArm.eulerAngles.y, (CatapultArm.eulerAngles.z - (AccelerationMultiplier * RotateSpeed * Time.deltaTime)));
            }
            else
            {
                Flinging = false;
            }
        }

        if (Retracting)
        {
            if (CatapultArm.eulerAngles.z < StartZRotation)
            {
                CatapultArm.eulerAngles = new Vector3(CatapultArm.eulerAngles.x, CatapultArm.eulerAngles.y, CatapultArm.eulerAngles.z + (RotateSpeed * Time.deltaTime));
            }
            else
            {
                Retracting = false;
            }
        }
    }

    public void LaunchCatapult() //to start launch process, used from button
    {
        Retracting = false;
        Flinging = true;
    }

    void SetupRotation()
    {
        StartZRotation = CatapultArm.localEulerAngles.z;
    }
}

This has some extra stuff in it I added to work with my project, so go to the thread linked in the script to see the original. That is a very fascinating thread that helped me a lot.

As you see from my example above, just having a useful script isn’t enough to make it work with your project; you also need to understand how to integrate it with your game. I used that script on a catapult, so I added things to coordinate that code with the code that makes the catapult arm move. I can’t tell you exactly what to do to make it work with your particular game; that’s something only you’ll know. Since every game is different, the process will also be different.

Thank you for your answer, I’m going to look at the code you sent and try to follow your advice about learning C# more deeply. Have a nice day :wink: