Физика

Материал из NeoAxis Wikipedia.

Перейти к: навигация, поиск

[править] Управляем моторами

Для того чтобы это заработало нужно создать новый type, применить к ниму этот класс, создать меш, и главное физическую модель с моторами имена которых должны быть такиме же как в этом классе, и чуть не забыл характер тоже тоесть Geared а не Servo!!!

Ну начнем!

//Управляем Маторами!//
 
//Привязка//
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Diagnostics;
using Engine;
using Engine.EntitySystem;
using Engine.MapSystem;
using Engine.MathEx;
using Engine.PhysicsSystem;
using Engine.Renderer;
 
 
//характер//
namespace GameEntities
{
   public class Vaz2108Type : UnitType //Класс//
   {
   }
   
   //Интелект//
   public class Vaz2108 : Unit
   {
       Vaz2108Type _type = null; public new Vaz2108Type Type { get { return _type; } }
      protected override void OnTick()
     {
        base.OnTick();
 
        if( Intellect != null )
           TickIntellect();
        }
//Здесь и так ясно что камера//
     protected override void OnRender( Camera camera )
     {
        base.OnRender( camera );
     }
      
     //Ну вот и самое сладкое - определяем маторы!//
     void TickIntellect()
     {
         
         
        {
           float throttle = 0; //сила должна быть равна нулю иначе будет движение без нажатия клавиш//
            
           //определяем клавиши//
           if( Intellect.IsControlKeyPressed( GameControlKeys.Left ) )
              throttle++;
           if( Intellect.IsControlKeyPressed( GameControlKeys.Right ) )
              throttle--;
 
           GearedMotor motor = PhysicsModel.GetMotor( "horizontalMotor" ) as GearedMotor;
           if( motor != null )
              motor.Throttle = throttle;
        }
        
         
         
        //Ну и остальные моторы также, если конечно они вам нужны!//
        //мотор номер 2//
        {
           float throttle = 0;
           if( Intellect.IsControlKeyPressed( GameControlKeys.Left ) )
              throttle++;
           if( Intellect.IsControlKeyPressed( GameControlKeys.Right ) )
              throttle--;

           GearedMotor motor = PhysicsModel.GetMotor( "horizontal1Motor" ) as GearedMotor;
           if( motor != null )
              motor.Throttle = throttle;
        }
         
        //третий мотор//
        {
           float throttle = 0;
           if( Intellect.IsControlKeyPressed( GameControlKeys.Forward ) )
              throttle++;
           if( Intellect.IsControlKeyPressed( GameControlKeys.Backward ) )
              throttle--;

           GearedMotor motor = PhysicsModel.GetMotor( "horizontal2Motor" ) as GearedMotor;
           if( motor != null )
              motor.Throttle = throttle;
        }
         
        //четвертый мотор//
        {
           float throttle = 0;
           if( Intellect.IsControlKeyPressed( GameControlKeys.Forward ) )
              throttle++;
           if( Intellect.IsControlKeyPressed( ControlKey.Backward ) )
              throttle--;

           GearedMotor motor = PhysicsModel.GetMotor( "horizontal3Motor" ) as GearedMotor;
           if( motor != null )
              motor.Throttle = throttle;
           //Ну вот и всё, осталось только скомпилить и применить этот класс к модели!// 
        }
     }
  }
}

Автор SergeyRX

Личные инструменты