Home Game Development unity – How can I Implement spin in billiard recreation?

unity – How can I Implement spin in billiard recreation?

0
unity – How can I Implement spin in billiard recreation?

[ad_1]

I’m unsure that you simply performed billiard or snooker earlier than.for those who performed it is 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 recreation

_39103267_snooker_spin_2_298

for instance distinction between Top spin and Back spin is:

Top spin

Record_2019_03_12_00_35_03_630

Back spin

Record_2019_03_12_00_35_39_151


Spin behaviour

for those who goal behind the ball you’ll be able to shoot the ball in all course

A


for those who goal closest to proper you’ll be able to simply goal the proper

B

for those who goal closest to left you’ll be able to simply goal the left

C


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

Top Spin

GetComponent<Rigidbody>().AddTorque(Vector3.again * cueStrength );
GetComponent<Rigidbody>().AddForceAtPosition(cueStick.ahead * cueStrength,remodel.place,ForceMode.Acceleration);

Record_2019_03_12_00_47_45_936

Back Spin

GetComponent<Rigidbody>().AddTorque(Vector3.ahead * cueStrength );
GetComponent<Rigidbody>().AddForceAtPosition(cueStick.ahead * cueStrength,remodel.place,ForceMode.Acceleration);

Record_2019_03_12_00_45_23_544

I observed that flyordie’s snooker did not use AddTorque.so I do not want reply that Implemented 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 connected 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 PrimaryBall : MonoBehaviour {

    non-public Vector3 FirstPos; // retailer first place as reset place
    public Transform 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 Start() {
        rigidbody = GetComponent<Rigidbody>();
        FirstPos = remodel.place;
    }


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

    }


    void SpinPressure(){
        SpinUsed = true;
        float F = ComebackForce(); // calculate comeback power
        CeaseBall(); // 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 CeaseBall(){
      rigidbody.velocity = Vector3.zero;
        rigidbody.angularVelocity = Vector3.zero;
    }


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

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

1.Ball goes Wrong 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 gradual generally

enter image description here

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

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here