Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit, 100.0f))
            {
                SomethingClicked = true;
                ClickedObject    = hit.collider.gameObject;
            }
        }
        if (ClickedObject != null)
        {
            var body = ClickedObject.GetComponent <CRigidBody>();


            Masstext.text  = "Mass:" + body.mMass.ToString();
            Acceltext.text = "Acceleration:" + body.mAcceleration.ToString();
            Veloctext.text = "Velocity:" + body.mVelocity.ToString();
            Forcetext.text = "Momentum :" + body.mMomentum.ToString();
        }

        if (Input.GetMouseButtonDown(1))
        {
            RaycastHit hit;
            Ray        rightray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(rightray, out hit, 100.0f))
            {
                SomethingClicked   = true;
                RightClickedObject = hit.collider.gameObject;
                prevmousepos       = Input.mousePosition;
            }
        }

        if (Input.GetMouseButtonUp(1))
        {
            currentmousepos = Input.mousePosition;
            Displacement    = prevmousepos - currentmousepos;
            Displacement.z  = 0;
            springforce     = -K * Displacement;

            RightClickedObject.GetComponent <CRigidBody>().ApplyForce(springforce);
        }
        if (Input.GetKey(KeyCode.L) && Time.timeSinceLevelLoad > cooldown)
        {
            var newobje = (GameObject)Instantiate(Cube, new Vector3(0, 20, 0), Quaternion.identity);
            physics.AddBody(newobje.GetComponent <CRigidBody>());
            cooldown = Time.timeSinceLevelLoad + 1.0f;
        }
        if (Input.GetKey(KeyCode.P) && Time.timeSinceLevelLoad > cooldown)
        {
            var newobje = (GameObject)Instantiate(Sphere, new Vector3(Camera.main.ScreenPointToRay(Input.mousePosition).origin.x, Camera.main.ScreenPointToRay(Input.mousePosition).origin.y, 0), Quaternion.identity);
            physics.AddBody(newobje.GetComponent <CRigidBody>());
            cooldown = Time.timeSinceLevelLoad + 1.0f;
        }
    }
Esempio n. 2
0
 public void Instanciate(MyPhysics physics)
 {
     mPosition = this.transform.position;
     mCollider = GetComponent <Collision>();
     mMass     = Mathf.Pow(mCollider.size, 3);
     physics.AddBody(this);
     Instanciated = true;
 }
Esempio n. 3
0
	public void Instanciate(MyPhysics physics)
	{
		mPosition = this.transform.position;
		mCollider = GetComponent<Collision>();
		mMass = Mathf.Pow (mCollider.size, 3);
		physics.AddBody (this);
		Instanciated = true;
	}