Giter Club home page Giter Club logo

ball-launcher's Introduction

BALL LAUNCHER by Axlope

en_logo - Experience dynamic physics interactions, touch-based controls, and an engaging game loop. Explore features like drag-and-release mechanics, continuous ball spawning, and device-friendly design for various resolutions.

tr_logo - Dinamik fizik etkileşimleri, dokunma tabanlı kontroller ve etkileyici bir oyun döngüsü deneyimi yaşayın. Sürükle ve bırak mekaniği, sürekli top oluşturma gibi özellikleri keşfedin ve çeşitli çözünürlükler için cihaz dostu tasarımıyla etkileşimde bulunun.

Gameplay Video

Key Features en_logo

  • Dynamic ball responding to gravity
  • Touchscreen input with coordinate tracking
  • Drag-and-release mechanics for launching
  • Continuous game loop with seamless ball spawning
  • Device-friendly gameplay on various resolutions using Cinemachine

Temel Özellikler tr_logo

  • Yerçekimine tepki veren dinamik top
  • Dokunmatik ekran girişi ve koordinat takibi
  • Sürükle ve bırak mekaniği ile fırlatma
  • Aralıksız oyun döngüsü ve kesintisiz top üretimi
  • Cinemachine kullanarak çeşitli çözünürlüklerde cihaz dostu oyun deneyimi

Unity Editor View

SCRIPTS

BallHandler.cs

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

namespace YourNamespace // Replace "YourNamespace" with your desired namespace name
{
    public class BallHandler : MonoBehaviour
    {
        [SerializeField] private GameObject ballPrefab;
        [SerializeField] private Rigidbody2D pivot;
        [SerializeField] private float DetachDelay;
        [SerializeField] private float respawnDelay;

        
        private Rigidbody2D currentBallRigidbody;
        private SpringJoint2D currentBallSprintJoint;

        private Camera mainCamera;
        private bool isDragging;

        // Start is called before the first frame update
        void Start()
        {
            mainCamera = Camera.main;

            SpawnNewBall();
        }

        // Update is called once per frame
        void Update()
        {
            if(currentBallRigidbody == null)
            {
                return;
            }

            if(!Touchscreen.current.primaryTouch.press.isPressed)
            {
                if(isDragging)
                {
                    LaunchBall();
                }

                isDragging = false;
                
                return;
            }

            isDragging = true;

            currentBallRigidbody.isKinematic = true;

            Vector2 touchPosition = Touchscreen.current.primaryTouch.position.ReadValue();
            Vector3 worldPosition = mainCamera.ScreenToWorldPoint(touchPosition);

            currentBallRigidbody.position = worldPosition;
        }

        private void SpawnNewBall()
        {
            GameObject ballInstance = Instantiate(ballPrefab, pivot.position, Quaternion.identity);

            currentBallRigidbody = ballInstance.GetComponent<Rigidbody2D>();
            currentBallSprintJoint = ballInstance.GetComponent<SpringJoint2D>();

            currentBallSprintJoint.connectedBody = pivot;

        }

        private void LaunchBall()
        {
            currentBallRigidbody.isKinematic = false;
            currentBallRigidbody = null;

            Invoke(nameof(DetachBall), DetachDelay);
        }

        private void DetachBall()
        {

            currentBallSprintJoint.enabled = false;
            currentBallSprintJoint = null;

            Invoke(nameof(SpawnNewBall), respawnDelay);
        }
    }
}

ball-launcher's People

Contributors

axlope avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.