コード例 #1
0
ファイル: PowerUpScript.cs プロジェクト: rawrimryno/Zambio
	// Use this for initialization
	void Start () {
//        gameController = GameControllerSingleton.get();
        rb = GetComponent<Rigidbody>();
        rb.AddRelativeTorque(0, initTorque, 0);
        rb.AddRelativeForce(0, initYForce, 0);
        initY = transform.position.y;
	}
コード例 #2
0
 static public int AddRelativeTorque(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 5)
         {
             UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l);
             System.Single         a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             System.Single a3;
             checkType(l, 4, out a3);
             UnityEngine.ForceMode a4;
             checkEnum(l, 5, out a4);
             self.AddRelativeTorque(a1, a2, a3, a4);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 4)
         {
             UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l);
             System.Single         a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             System.Single a3;
             checkType(l, 4, out a3);
             self.AddRelativeTorque(a1, a2, a3);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 3)
         {
             UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l);
             UnityEngine.Vector3   a1;
             checkType(l, 2, out a1);
             UnityEngine.ForceMode a2;
             checkEnum(l, 3, out a2);
             self.AddRelativeTorque(a1, a2);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 2)
         {
             UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l);
             UnityEngine.Vector3   a1;
             checkType(l, 2, out a1);
             self.AddRelativeTorque(a1);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
コード例 #3
0
ファイル: Mechanism.cs プロジェクト: rusticgames/rts
 public void applyAngularForce(Rigidbody toBody, Vector3 desiredTorque, bool relative)
 {
     if(relative) {
         toBody.AddRelativeTorque(desiredTorque, this.angularForceMode);
     }
     else {
         toBody.AddTorque(desiredTorque, this.angularForceMode);
     }
 }
コード例 #4
0
ファイル: Asteroid.cs プロジェクト: rymotion/hackpoly_game
	// Use this for initialization
	void Start () {
		rb = GetComponent<Rigidbody>();
		
		rb.velocity = new Vector2(Random.Range(-maxSpeed, maxSpeed), Random.Range(-maxSpeed, maxSpeed));
		rb.AddRelativeTorque(Random.Range(0.0f, maxRotation), Random.Range(0.0f, maxRotation), Random.Range(0.0f, maxRotation));
		transform.localScale = new Vector3(Random.Range(minScale, maxScale), Random.Range(minScale, maxScale), Random.Range(minScale, maxScale));
		
		rb.mass = rb.mass * transform.localScale.x * transform.localScale.y * transform.localScale.z;
	}
コード例 #5
0
 static public int AddRelativeTorque(IntPtr l)
 {
     try{
         if (matchType(l, 2, typeof(UnityEngine.Vector3), typeof(UnityEngine.ForceMode)))
         {
             UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l);
             UnityEngine.Vector3   a1;
             checkType(l, 2, out a1);
             UnityEngine.ForceMode a2;
             checkEnum(l, 3, out a2);
             self.AddRelativeTorque(a1, a2);
             return(0);
         }
         else if (matchType(l, 2, typeof(UnityEngine.Vector3)))
         {
             UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l);
             UnityEngine.Vector3   a1;
             checkType(l, 2, out a1);
             self.AddRelativeTorque(a1);
             return(0);
         }
         else if (matchType(l, 2, typeof(System.Single), typeof(System.Single), typeof(System.Single)))
         {
             UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l);
             System.Single         a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             System.Single a3;
             checkType(l, 4, out a3);
             self.AddRelativeTorque(a1, a2, a3);
             return(0);
         }
         else if (matchType(l, 2, typeof(System.Single), typeof(System.Single), typeof(System.Single), typeof(UnityEngine.ForceMode)))
         {
             UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l);
             System.Single         a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             System.Single a3;
             checkType(l, 4, out a3);
             UnityEngine.ForceMode a4;
             checkEnum(l, 5, out a4);
             self.AddRelativeTorque(a1, a2, a3, a4);
             return(0);
         }
         LuaDLL.luaL_error(l, "No matched override function to call");
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
コード例 #6
0
	// Use this for initialization
	void Start ()
    {
        //Start spinning
        rb = GetComponent<Rigidbody>();
        //Spinning might be random on some, could be fixed, use a bool to decide which behaviour to use
        if(randomSpin)
        {
            spinDir = new Vector3(Random.Range(0, 2), Random.Range(0, 2), Random.Range(0, 2)).normalized;
            spinForce = Random.Range(10, 100);
        }
        rb.AddRelativeTorque(spinDir * spinForce * Time.smoothDeltaTime);
    }
コード例 #7
0
    static int AddRelativeTorque(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2)
            {
                UnityEngine.Rigidbody obj  = (UnityEngine.Rigidbody)ToLua.CheckObject(L, 1, typeof(UnityEngine.Rigidbody));
                UnityEngine.Vector3   arg0 = ToLua.ToVector3(L, 2);
                obj.AddRelativeTorque(arg0);
                return(0);
            }
            else if (count == 3)
            {
                UnityEngine.Rigidbody obj  = (UnityEngine.Rigidbody)ToLua.CheckObject(L, 1, typeof(UnityEngine.Rigidbody));
                UnityEngine.Vector3   arg0 = ToLua.ToVector3(L, 2);
                UnityEngine.ForceMode arg1 = (UnityEngine.ForceMode)ToLua.CheckObject(L, 3, typeof(UnityEngine.ForceMode));
                obj.AddRelativeTorque(arg0, arg1);
                return(0);
            }
            else if (count == 4)
            {
                UnityEngine.Rigidbody obj = (UnityEngine.Rigidbody)ToLua.CheckObject(L, 1, typeof(UnityEngine.Rigidbody));
                float arg0 = (float)LuaDLL.luaL_checknumber(L, 2);
                float arg1 = (float)LuaDLL.luaL_checknumber(L, 3);
                float arg2 = (float)LuaDLL.luaL_checknumber(L, 4);
                obj.AddRelativeTorque(arg0, arg1, arg2);
                return(0);
            }
            else if (count == 5)
            {
                UnityEngine.Rigidbody obj = (UnityEngine.Rigidbody)ToLua.CheckObject(L, 1, typeof(UnityEngine.Rigidbody));
                float arg0 = (float)LuaDLL.luaL_checknumber(L, 2);
                float arg1 = (float)LuaDLL.luaL_checknumber(L, 3);
                float arg2 = (float)LuaDLL.luaL_checknumber(L, 4);
                UnityEngine.ForceMode arg3 = (UnityEngine.ForceMode)ToLua.CheckObject(L, 5, typeof(UnityEngine.ForceMode));
                obj.AddRelativeTorque(arg0, arg1, arg2, arg3);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.Rigidbody.AddRelativeTorque"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
コード例 #8
0
        public override void OnFixedUpdate()
        {
            if (rigidbody != null)
            {
                switch (space)
                {
                case Space.World:
                    rigidbody.AddTorque(owner.GetValue(torque), forceMode);
                    break;

                case Space.Self:
                    rigidbody.AddRelativeTorque(owner.GetValue(torque), forceMode);
                    break;
                }
            }
            Finish();
        }
コード例 #9
0
ファイル: Ball.cs プロジェクト: joouur/3DPONG
        public void Awake()
        {
            BallRb = GetComponent<Rigidbody>();
            //BallRb.useGravity = false;
            //BallRb.AddRelativeForce(Vector3.one * 500);
            if (startSpeed == 0)
                startSpeed = -15.0f;
            BallRb.maxAngularVelocity = maxAngularSpeed;
            BallRb.AddRelativeTorque(Vector3.one);
            BallRb.velocity = new Vector3(0, startSpeed, 0);
            grav = new Vector3(0, -9.81f, 0);

            playerContact = GameObject.FindGameObjectWithTag("Player").GetComponent<PaddleContact>();
            enemyContact = GameObject.FindGameObjectWithTag("Enemy").GetComponent<PaddleContact>();

            playerContact.ball = this;
            enemyContact.ball = this;

            ballAudio = GetComponent<AudioSource>() as AudioSource;
        }
コード例 #10
0
	/// <summary>
	/// spawns the 'ShellPrefab' gameobject and gives it a velocity
	/// </summary>
	protected virtual void EjectShell()
	{

		if (ShellPrefab == null)
			return;

		// spawn the shell
		GameObject s = null;

		s = (GameObject)vp_Utility.Instantiate(ShellPrefab,
			((m_ShellEjectSpawnPoint == null)
			? FirePosition + m_ProjectileSpawnPoint.transform.TransformDirection(ShellEjectPosition)	// we have no shell eject object: use old logic
			: m_ShellEjectSpawnPoint.transform.position)												// we have a shell eject object: use new logic
			, m_ProjectileSpawnPoint.transform.rotation);

		s.transform.localScale = m_ActualShellScale;
		vp_Layer.Set(s.gameObject, vp_Layer.Debris);

		// send it flying
		m_ShellRigidbody = s.GetComponent<Rigidbody>();
		if (m_ShellRigidbody == null)
			return;
			
		Vector3 force = ((m_ShellEjectSpawnPoint == null) ?
		transform.TransformDirection(ShellEjectDirection).normalized * ShellEjectVelocity	// we have a shell eject object: use new logic
		: m_ShellEjectSpawnPoint.transform.forward.normalized * ShellEjectVelocity);		// we have no shell eject object: use old logic

		// toss the shell
		m_ShellRigidbody.AddForce(force, ForceMode.Impulse);
		
		// make the shell inherit the current speed of the controller (if any)
		if (m_CharacterController)	// TODO: should use a velocity calculated from operator transform
		{

			Vector3 velocityForce = (m_CharacterController.velocity);
			m_ShellRigidbody.AddForce(velocityForce, ForceMode.VelocityChange);

		}

		// add random spin if user-defined
		if (ShellEjectSpin > 0.0f)
		{
			if (Random.value > 0.5f)
				m_ShellRigidbody.AddRelativeTorque(-Random.rotation.eulerAngles * ShellEjectSpin);
			else
				m_ShellRigidbody.AddRelativeTorque(Random.rotation.eulerAngles * ShellEjectSpin);
		}

	}
コード例 #11
0
 /// <summary>
 /// Applies the force.
 /// </summary>
 /// <param name="body">The body.</param>
 public override void ApplyForce(Rigidbody body) {
   var torqueVector = Random.insideUnitSphere * Amount;
   body.AddRelativeTorque(torqueVector, ForceMode.Impulse);
 }