Esempio n. 1
0
    /**
     * @brief Updates ball's movements and instantiates new ball objects when player press space.
     **/
    public override void OnSyncedUpdate()
    {
        FP   hor = (FP)TrueSyncInput.GetInt(INPUT_KEY_HORIZONTAL) / 100;
        FP   ver = (FP)TrueSyncInput.GetInt(INPUT_KEY_VERTICAL) / 100;
        bool currentCreateState = TrueSyncInput.GetInt(INPUT_KEY_CREATE) == 1;

        // Instantiates a new ball belonging to current player if the following criteria is true
        if (!lastCreateState && currentCreateState && !createdRuntime)
        {
            SimpleControl otherSP = TrueSyncManager.SyncedInstantiate(prefab, tsTransform.position, tsTransform.rotation).GetComponent <SimpleControl>();
            otherSP.createdRuntime = true;
            otherSP.owner          = owner;

            lastCreateState = currentCreateState;

            return;
        }

        TSVector forceToApply = TSVector.zero;

        if (FP.Abs(hor) > FP.Zero)
        {
            forceToApply.x = hor / 3;
        }

        if (FP.Abs(ver) > FP.Zero)
        {
            forceToApply.z = ver / 3;
        }

        controlledBody.AddForce(forceToApply, ForceMode.Impulse);

        lastCreateState = currentCreateState;
    }
Esempio n. 2
0
    private void UpdateStandingPose()
    {
        JitterPhysicsTools.AlignToVector(spine, spine.tsTransform.forward, direction.normalized, 0.001f, 12.0f);
        JitterPhysicsTools.AlignToVector(head, head.tsTransform.forward, direction.normalized, 0.001f, 12.0f);
        JitterPhysicsTools.AlignToVector(pelvis, pelvis.tsTransform.forward, direction.normalized, 0.001f, 12.0f);

        head.AddForce(TSVector.up * 3000);
        spine.AddForce(TSVector.up * 3000);
        pelvis.AddForce(TSVector.up * 3000);

        leftLeg.AddForce(TSVector.down * 3000);
        rightLeg.AddForce(TSVector.down * 3000);

        leftFoot.AddForce(TSVector.down * 1500);
        rightFoot.AddForce(TSVector.down * 1500);
    }
Esempio n. 3
0
    public override void OnSyncedUpdate()
    {
        base.OnSyncedUpdate();

        FP   hor = (FP)TrueSyncInput.GetInt(INPUT_KEY_HORIZONTAL) / 100;
        FP   ver = (FP)TrueSyncInput.GetInt(INPUT_KEY_VERTICAL) / 100;
        bool currentCreateState = TrueSyncInput.GetBool(INPUT_KEY_CREATE);

        bool allowInput = false;

        if (hor != 0 || ver != 0)
        {
            allowInput = true;
            //Debug.Log("allow input is true: " + hor + " : " + ver);


            direction = new TSVector(hor, 0, ver);
        }


        //counter++;

        //if (counter > 10)
        //{
        //Debug.Log("testing spine and pevlis");


        if (allowInput)
        {
            //spring.AddForce(TSVector.down * 0);
            ball.AddForce(TSVector.down * 100);
            TSVector a = new TSVector(ver, 0, -hor);

            ball.angularVelocity = a * speedRatio;

            //Debug.Log(ball.angularVelocity + " a: " + a);

            if (ball.angularVelocity.magnitude > 50)
            {
                ball.angularVelocity = previousAngularVelocity;
            }


            previousAngularVelocity = ball.angularVelocity;

            UpdateRunPose();
        }
        else
        {
            ball.angularVelocity = TSVector.zero;
            UpdateStandingPose();
        }

        ////pelvis.angularVelocity = TSVector.zero;
        //pelvis.velocity = TSVector.zero;
        //pelvis.MovePosition(new TSVector(ball.position.x, pelvis.position.y, ball.position.z));
    }
 // Update is called once per frame
 void FixedUpdate()
 {
     if (Input.GetKeyDown(KeyCode.T))
     {
         rigidBody.AddTorque(torque.ToTSVector());
     }
     if (Input.GetKeyDown(KeyCode.F))
     {
         rigidBody.AddForce(force.ToTSVector());
     }
 }
Esempio n. 5
0
 void simulation()
 {
     if (FrameCount < 1000)
     {
         tsRigidBody.AddForce(new TSVector(0.0, 0.0, -2.2), ForceMode.Impulse);
     }
     else if (FrameCount < 2000)
     {
         tsRigidBody.AddForce(new TSVector(0.0, 0.0, 2.2), ForceMode.Impulse);
     }
     else if (FrameCount < 2400)
     {
         tsRigidBody.AddForce(new TSVector(2.2, 0.0, 0.0), ForceMode.Impulse);
     }
     else if (FrameCount < 2800)
     {
         tsRigidBody.AddForce(new TSVector(-2.2, 0.0, 0.0), ForceMode.Impulse);
     }
     else if (FrameCount < 3000)
     {
         tsRigidBody.AddForce(new TSVector(-2.2, 0.0, -2.2), ForceMode.Impulse);
     }
     else
     {
         tsRigidBody.AddForce(new TSVector(0.0, 0.0, 0.0), ForceMode.Impulse);
     }
 }
Esempio n. 6
0
 void Gravity()
 {
     rigidBody.AddForce(TSVector.down * 10, ForceMode.Force);
 }
Esempio n. 7
0
 void simulation()
 {
     if (FrameCount > 3900)
     {
         tsRigidBody.AddForce(new TSVector(0.0, 0.0, -1.2), ForceMode.Impulse);
         PhysicsManager.instance.UpdateStep();
         FrameCount--;
     }
     else if (FrameCount > 3800)
     {
         tsRigidBody.AddForce(new TSVector(0.0, 0.0, 1.2), ForceMode.Impulse);
         PhysicsManager.instance.UpdateStep();
         FrameCount--;
     }
     else if (FrameCount > 2800)
     {
         tsRigidBody.AddForce(new TSVector(1.2, 0.0, 0.0), ForceMode.Impulse);
         PhysicsManager.instance.UpdateStep();
         FrameCount--;
     }
     else if (FrameCount > 2400)
     {
         tsRigidBody.AddForce(new TSVector(-1.2, 0.0, 0.0), ForceMode.Impulse);
         PhysicsManager.instance.UpdateStep();
         FrameCount--;
     }
     else if (FrameCount > 1400)
     {
         tsRigidBody.AddForce(new TSVector(-1.2, 0.0, -1.2), ForceMode.Impulse);
         PhysicsManager.instance.UpdateStep();
         FrameCount--;
     }
     else if (FrameCount > 0)
     {
         tsRigidBody.AddForce(new TSVector(0.0, 0.0, 0.0), ForceMode.Impulse);
         PhysicsManager.instance.UpdateStep();
         FrameCount--;
     }
 }
Esempio n. 8
0
 // Update is called once per frame
 public override void OnSyncedUpdate()
 {
     spine.AddForce(new Vector3(0, 500, 0).ToTSVector());
 }
Esempio n. 9
0
    public override void OnSyncedStart()
    {
        rigidBody = GetComponent <TSRigidBody> ();

        rigidBody.AddForce(tsTransform.forward * bulletSpeed, ForceMode.Impulse);
    }