Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// Code for rotation
- /// Set target
- Vector3 TargetPosition(2.0f,2.0f,2.0f);
- /// Get Cross product to get a angle
- Vector3 currentForwardUnit=Vector3(1.0f,1.0f,1.0f);
- Vector3 newForwardUnit = Vector3(TargetPosition-ThisBody->GetPosition()).Normalized();
- /// Get Rotation and Axis
- Vector3 rotAxis= currentForwardUnit.CrossProduct(newForwardUnit);
- float rotAngle=acos(currentForwardUnit.DotProduct(newForwardUnit));
- /// Create a quaternion
- Quaternion rot(rotAngle,rotAxis);
- /// Set Rotation
- ThisBody->SetRotation(ThisBody->GetRotation()*rot);
- ///////// drone creation
- /// Create needed filenames
- String temporarymodelfilename;
- String temporarytexturefilename;
- Node * ObjectStaticNode;
- StaticModel * ObjectStaticModel;
- /// first one
- temporaryfilename.Clear();
- temporaryfilename.Append("Resources/Models/");
- /// Create a resource filename
- temporaryfilename.Append("ExoComp2");
- /// wall or other component
- temporarymodelfilename=temporaryfilename+String(".mdl");
- temporarytexturefilename=temporaryfilename+String(".txt");
- ObjectStaticNode= Existence->scene_ -> CreateChild("ExoComp2");
- ObjectStaticModel = ObjectStaticNode->CreateComponent<StaticModel>();
- ObjectStaticModel ->SetModel(cache->GetResource<Model>(temporarymodelfilename));
- ObjectStaticModel ->ApplyMaterialList(temporarytexturefilename);
- ObjectStaticModel ->SetCastShadows(true);
- ObjectStaticNode->SetPosition(Vector3(4,1.5f,1));
- /// Create rigidbody, and set non-zero mass so that the body becomes dynamic
- RigidBody * ObjectRigidBody = ObjectStaticNode->CreateComponent<RigidBody>();
- ObjectRigidBody->SetCollisionLayer(1);
- /// Turn off Gravity
- ObjectRigidBody->SetMass(1.2f);
- ObjectRigidBody->SetUseGravity(true);
- ObjectRigidBody->SetAngularDamping(0.6f);
- ObjectRigidBody->SetLinearDamping(0.6f);
- /// Set zero angular factor so that physics doesn't turn the character on its own.
- /// Instead we will control the character yaw manually
- ObjectRigidBody->SetAngularFactor(Vector3::ONE);
- /// Set the rigidbody to signal collision also when in rest, so that we get ground collisions properly
- ObjectRigidBody->SetCollisionEventMode(COLLISION_ALWAYS);
- Model * ExoComp2Collision = cache->GetResource<Model>(String("Resources/Models/ExoComp2Collision.mdl"));
- /// Set a capsule shape for collision
- CollisionShape* ObjectShape = ObjectStaticNode->CreateComponent<CollisionShape>();
- /// Set shape collision
- ObjectShape->SetConvexHull(ExoComp2Collision);
- ObjectShape->SetLodLevel(1);
- ObjectShape->SetMargin(0.1f);
- /// Created Drone
- Drone * CreatedDrone = ObjectStaticNode->CreateComponent<Drone>();
- /// Create Drone information
- DroneInformation SetDrone;
- SetDrone.AlienAllianceAligned=0;
- SetDrone.AlienRace=0;
- SetDrone.DroneType=Drone100Beta;
- SetDrone.Name = String("test");
- CreatedDrone->SetNode(ObjectStaticNode);
- CreatedDrone->SetParameters(SetDrone);
- CreatedDrone->Initialize();
- ResourceNodeComponent * DroneResourceComponent2=ObjectStaticNode -> CreateComponent<ResourceNodeComponent>();
- DroneResourceComponent2->SetResourceComponentNameType(String("ExoComp1"), RCType_Drone);
- DroneResourceComponent2->MapResources(Existence->ResourcesManager);
- ObjectStaticNode->CreateComponent<InteractObject>();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement