21.4 C
New York
Tuesday, September 9, 2025

unity – How can I Implement spin in billiard sport?


I am unsure that you just performed billiard or snooker earlier than.in case you performed it’s best to learn about spin.
however anyway if you do not know about it you’ll be able to see it in this video

I wish to Implement spin like this sport

for instance distinction between Prime spin and Again spin is:

Prime spin

Record_2019_03_12_00_35_03_630

Again spin

Record_2019_03_12_00_35_39_151


Spin behaviour

in case you goal behind the ball you’ll be able to shoot the ball in all course

A


in case you goal closest to proper you’ll be able to simply goal the correct

B

in case you goal closest to left you’ll be able to simply goal the left

C


I discovered a similar Challenge that used Torque in stackoverflow however I do not know why did not work!

Prime Spin

GetComponent().AddTorque(Vector3.again * cueStrength );
GetComponent().AddForceAtPosition(cueStick.ahead * cueStrength,rework.place,ForceMode.Acceleration);

Record_2019_03_12_00_47_45_936

Again Spin

GetComponent().AddTorque(Vector3.ahead * cueStrength );
GetComponent().AddForceAtPosition(cueStick.ahead * cueStrength,rework.place,ForceMode.Acceleration);

Record_2019_03_12_00_45_23_544

I seen that flyordie’s snooker did not use AddTorque.so I do not want reply that Applied with AddTorque.


What I attempted

I add joystick to pick out spin angle

enter image description here

then I apply spin power ( It appears my spin works however generally did not work that I hooked up video in finish of my query).

enter image description here
enter image description here
enter image description here
enter image description here

that is my code:

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;

public class MainBall : MonoBehaviour {

    non-public Vector3 FirstPos; // retailer first place as reset place
    public Remodel SpinRoator; // spin rotator cylinder that present spin angle
    non-public Rigidbody rigidbody;
    public bool SpinUsed; // spin ought to use as soon as
    non-public float v2;

    non-public void Begin() {
        rigidbody = GetComponent();
        FirstPos = rework.place;
    }


    //After objective reset ball place
    public void ResetPos(){
        rigidbody.velocity = Vector3.zero;
        rigidbody.angularVelocity = Vector3.zero;
        rework.place = FirstPos;

    }


    void SpinForce(){
        SpinUsed = true;
        float F = ComebackForce(); // calculate comeback power
        StopBall(); // cease ball
        rigidbody.AddForce(SpinRoator.ahead*F);// apply spin power
    }


    // calculating return power after hitting f = m.a
    float ComebackForce(){
        var m = rigidbody.mass;
    var v1 = rigidbody.velocity.magnitude;

    var a = (v1 - v2) / Time.deltaTime;
        var F = m * a;
        v2 = rigidbody.velocity.magnitude;
        return F;
    }

    //cease ball
    public void StopBall(){
      rigidbody.velocity = Vector3.zero;
        rigidbody.angularVelocity = Vector3.zero;
    }


non-public void OnCollisionEnter(Collision different) {
    if(different.collider.tag == "Ball" || different.collider.tag == "ColorfulBall"){
    if(!SpinUsed){
    SpinForce();
    }
    }
}
}

It appears works appropriately however My Drawback is typically Spin do not work appropriately you’ll be able to see this video that exhibit this downside.my ball goes flawed course of spin!!!

1.Ball goes Improper generally

enter image description here

as you’ll be able to see in above gif ball goes flawed course!!! ball ought to go alongside yellow cylinder however I do not know what’s downside of my code!!!

1.Ball goes sluggish generally

enter image description here

one other downside is comeback power is sluggish generally!!!
I calculate comeback power F = m.a however why is it sluggish?!

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles