Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Drop Proyectile Physics Effect

Discussion in 'Physics' started by davidpkami, May 7, 2019.

  1. davidpkami

    davidpkami

    Joined:
    Dec 30, 2017
    Posts:
    9
    Hi! I am trying to shoot a shell from a cannon and play with the drop, but I dont know how to make the Xample2 image efect, becase I cant modify the center of mass.

    Xample1 is the efect that I have now in Unity.

    I was trying to use this code but doesnt works.


    public class Center_Of_Mass : MonoBehaviour
    {

    public Vector2 CenterOfMass2;
    public bool Awake;
    public float AngularSpeed;

    protected Rigidbody2D r;

    // Start is called before the first frame update
    void Start()
    {
    r = GetComponent<Rigidbody2D>();
    }



    // Update is called once per frame
    void Update()
    {
    r.centerOfMass = CenterOfMass2;
    r.WakeUp();
    Awake = !r.IsSleeping();
    }

    private void OnDrawGizmos()
    {
    Gizmos.color = Color.red;
    Gizmos.DrawSphere(transform.position + transform.rotation * CenterOfMass2, 0.1f);
    }
    }
     

    Attached Files:

  2. davidpkami

    davidpkami

    Joined:
    Dec 30, 2017
    Posts:
    9
    I tried to use another code, but I do not reach my objetive.

    The new code rotate de Shell / time, but it doesnt work with the distance or angle of the shoot. The shell rotate at the same speed, doesnt matter the other features.

    I have reached a similar effect, but it is far to be perfect:


    -----------------------

    public class P1_Mover : MonoBehaviour
    {

    public float speed;
    public Rigidbody2D rb;
    public float turnSpeed;


    // Start is called before the first frame update
    void Start()
    {
    rb = GetComponent<Rigidbody2D>();
    rb.velocity = transform.right * speed;

    //Vector2 force = new Vector2(speed, 0);
    //rb.AddForce(force);
    }

    private void Update()
    {
    transform.rotation = Quaternion.Euler(Vector3.forward * rb.velocity.y * turnSpeed);
    }

    }

    --------------------------------
    The problem: Example1.png Example2.png
    This is the effect I want to reach
     
    Last edited: May 25, 2019
  3. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Why are you multiplying by velocity.y?
    Just set 'transform.forward' to 'velocity.normalized'.
     
  4. davidpkami

    davidpkami

    Joined:
    Dec 30, 2017
    Posts:
    9
    I want to reach the curve drop efect. [Example2]

    In the video I am showing that I have reached a similar effect, but it is far to be perfect.
     

    Attached Files:

  5. davidpkami

    davidpkami

    Joined:
    Dec 30, 2017
    Posts:
    9
    Still no have solution