示例#1
0
    public void CharacterShoot()
    {
        if (isUsingPlane)
        {
            characterFly();
        }
        else
        {
            iceBolt = Object.Instantiate(projectile);
            var orb = transform.GetChild(1);
            iceBolt.transform.position = new Vector3(orb.position.x + 0.05f, orb.transform.position.y + 0.2f, orb.position.z);
            //iceBolt.transform.position = new Vector3(transform.position.x, transform.position.y - orb.transform.position.y, transform.position.y);

            TrajectoryHelper icePath = iceBolt.GetComponent <TrajectoryHelper>();
            icePath.throwAngle = shootAngle;
            icePath.isPlane    = false;
            //Debug.log
            if (direction < 0)
            {
                icePath.throwAngle = 180 + shootAngle;
            }

            icePath.throwForce = shootForce;
            icePath.SendMessage("Shoot");
        }
    }
示例#2
0
    private void Update()
    {
        if (!started || Helper == null)
        {
            return;
        }

        chrono += Time.deltaTime;
        if (chrono >= 1)
        {
            chrono = 0;
            currentTime++;
            if (lastHelper && Vector3.Distance(transform.position, lastHelper.transform.position) <= HelpersThreshold)
            {
                lastHelper.AddFork(currentTime);
                return;
            }

            if (Vector3.Distance(transform.position, initialPosition) < HelpersThreshold)
            {
                return;
            }

            TrajectoryHelper helperGo = Instantiate(Helper, transform);
            helperGo.transform.SetParent(null);
            helperGo.transform.rotation = Quaternion.identity;
            helperGo.Setup(currentTime);
            helpers.Add(helperGo);
            lastHelper = helperGo;
        }
    }
 private void Visualize(Vector3 velocity)
 {
     for (int i = 0; i < dotCount; i++)
     {
         Vector3 pos = TrajectoryHelper.CalculatePosInTime(transform.position, velocity, i / (float)dotCount);
         lineDotList[i].transform.position = pos;
     }
 }
示例#4
0
    private void Update()
    {
        if (aiBrain.targetPosition != Vector3.zero && aiBrain.CanShoot)
        {
            Vector3 velocity =
                TrajectoryHelper.CalculateVelocity(aiBrain.targetPosition, transform.position, shootTime);

            Shoot(velocity);
            aiBrain.targetPosition = Vector3.zero;
        }
    }
示例#5
0
    public void JumpToRandomPlatform()
    {
        rigidbody.velocity = new Vector3();
        Debug.Log(Platform.Platforms.Count);
        int      randomPlatformIndex = Random.Range(0, Platform.Platforms.Count);
        Platform platform            = Platform.Platforms[randomPlatformIndex];

        if (platform == lastPlatform)
        {
            randomPlatformIndex = (randomPlatformIndex + 1) % Platform.Platforms.Count;
            platform            = Platform.Platforms[randomPlatformIndex];
        }
        lastPlatform = platform;

        Vector3 velocity = TrajectoryHelper.GetTrajectoryVelocity(transform.position, platform.JumpTo, 2.0f, Physics.gravity);

        rigidbody.AddForce(velocity, ForceMode.Impulse);
    }
示例#6
0
    public void characterFly()
    {
        iceBolt = Object.Instantiate(GameObject.Find("paper_plane"));
        iceBolt.SetActive(true);
        var orb = transform.GetChild(1);

        iceBolt.transform.position = new Vector3(orb.position.x + 1, orb.transform.position.y + 1, orb.position.z);
        //iceBolt.transform.position = new Vector3(transform.position.x, transform.position.y - orb.transform.position.y, transform.position.y);

        TrajectoryHelper icePath = iceBolt.GetComponent <TrajectoryHelper>();

        icePath.throwAngle = shootAngle;
        //Debug.log
        if (direction < 0)
        {
            icePath.throwAngle = 180 + shootAngle;
        }

        icePath.throwForce = shootForce;
        icePath.SendMessage("Shoot");
    }
    private Vector3 LaunchBall()
    {
        Vector3    Velocity;
        RaycastHit hit;
        Ray        rayToTarget = cam.ScreenPointToRay(Input.mousePosition);
        bool       isHit       = Physics.Raycast(rayToTarget, out hit, shootRange, shootLayer);

        if (isHit)
        {
            cursor.transform.position = hit.point;
            Velocity = TrajectoryHelper.CalculateVelocity(hit.point, transform.position, shootTime);
        }
        else
        {
            Vector3 raycastLastPoint = transform.position + rayToTarget.direction * shootRange;
            Velocity = TrajectoryHelper.CalculateVelocity(raycastLastPoint, transform.position, shootTime);
        }

        cursor.SetActive(isHit);

        Visualize(Velocity);

        return(Velocity);
    }