[Orxonox-commit 7291] r11908 - code/branches/OrxyRoad_FS18/src/modules/orxyroad

jacobsr at orxonox.net jacobsr at orxonox.net
Thu Apr 26 15:22:59 CEST 2018


Author: jacobsr
Date: 2018-04-26 15:22:59 +0200 (Thu, 26 Apr 2018)
New Revision: 11908

Modified:
   code/branches/OrxyRoad_FS18/src/modules/orxyroad/OrxyRoadShip.cc
   code/branches/OrxyRoad_FS18/src/modules/orxyroad/OrxyRoadShip.h
Log:
changed controlls

Modified: code/branches/OrxyRoad_FS18/src/modules/orxyroad/OrxyRoadShip.cc
===================================================================
--- code/branches/OrxyRoad_FS18/src/modules/orxyroad/OrxyRoadShip.cc	2018-04-26 13:21:23 UTC (rev 11907)
+++ code/branches/OrxyRoad_FS18/src/modules/orxyroad/OrxyRoadShip.cc	2018-04-26 13:22:59 UTC (rev 11908)
@@ -50,13 +50,18 @@
         lastTimeFront = 0;
         lastTimeLeft = 0;
         lastTime = 0;
+        steeredLeft = false;
+        steeredRight = false;
+        forward = false;
+        backward = false;
     }
 
     void OrxyRoadShip::tick(float dt)
     {
-        orxout(user_info) << "This is some cool output!" << endl;
+        //orxout(user_info) << "This is some cool output!" << endl;
 
         Vector3 pos = getPosition();
+        Vector3 pos1 = getPosition();
 
         //Movement calculation
         lastTimeFront += dt * damping;
@@ -63,19 +68,42 @@
         lastTimeLeft += dt * damping;
         lastTime += dt;
 
-        velocity.x = interpolate(clamp(lastTimeLeft, 0.0f, 1.0f), desiredVelocity.x, 0.0f);
-        velocity.y = interpolate(clamp(lastTimeFront, 0.0f, 1.0f), desiredVelocity.y, 0.0f);
+        
+        //velocity.x = interpolate(clamp(lastTimeLeft, 0.0f, 1.0f), desiredVelocity.x, 0.0f);
+        //velocity.y = interpolate(clamp(lastTimeFront, 0.0f, 1.0f), desiredVelocity.y, 0.0f);
 
         //Execute movement
+        
         if (this->hasLocalController())
         {
             float dist_y = velocity.y * dt;
+            //forward backwards movement
+            if(forward){
+                if(velocity.y < 200){// Limit for max velocity
+                    velocity.y += 10;
+                }
+                
+
+            }else if(backward){
+                if(velocity.y > 10){
+                     velocity.y -= 10; 
+                }else {
+                    velocity.y = 0; // Prevent players from going backwards
+                }
+                          
+            }else {
+                velocity.y = 0.9 * velocity.y;//reduce speed
+            }
+
+
+
+
             //float dist_x = velocity.x * dt;
-            if(dist_y + posforeward > -42*3 && dist_y + posforeward < 42*6)
-                posforeward += dist_y;
-            else
-            {
-                velocity.y = 0;
+            //if(dist_y + posforeward > -42*3 && dist_y + posforeward < 42*6)
+              //  posforeward += dist_y;
+            //else
+            //{
+                //velocity.y = 0;
                 // restart if game ended
 /*
                 if (getGame())
@@ -84,18 +112,41 @@
                         getGame()->start();
                         return;
                     }*/
+            //}
+
+            //Left right steering
+
+
+            if(steeredLeft){
+                velocity.x += 100;
+                steeredLeft = false;
+
+            }else if(steeredRight) {
+                velocity.x += -100;
+                steeredRight = false;
+            }else {
+                if(velocity.x < -2 || velocity.x > 2 ){
+                    velocity.x  = velocity.x *0.9;
+                }else{
+                    velocity.x += 0;
+                }
+                
             }
 
-            pos += Vector3(1000 + velocity.y, 0, velocity.x) * dt;
+            pos += Vector3(velocity.y, 0, velocity.x) * dt;
+            
         }
 
 
+
         // Camera
         Camera* camera = this->getCamera();
         if (camera != nullptr)
         {
-            // camera->setPosition(Vector3(-pos.z, -posforeward, 0));
-            camera->setOrientation(Vector3::UNIT_Z, Degree(0));
+            //camera->setPosition(Vector3(pos1.x - 10 ,50,0));
+            //camera->setOrientation(Vector3(-1,-1,0), Degree(45));
+            //camera->setOrientation(Vector3(-1,-1,-1), Degree(0));
+           camera->setOrientation(Vector3::UNIT_Z, Degree(0));
         }
 
 
@@ -128,6 +179,15 @@
 
     void OrxyRoadShip::moveFrontBack(const Vector2& value)
     {
+        this->steering_.z -= value.x ;
+        if(value.x > 0){
+            forward  = true;
+            backward = false;
+        }else if(value.x < 0){
+            forward = false;
+            backward = true;
+        }
+        
         //lastTimeFront = 0;
         //desiredVelocity.y = value.y * speed * 42;
 
@@ -135,12 +195,25 @@
 
     void OrxyRoadShip::moveRightLeft(const Vector2& value)
     {
-        lastTimeLeft = 0;
-        desiredVelocity.x = value.x * speed;
+        this->steering_.x += value.x;
+        if(value.x==-1){
+            steeredLeft = false;
+            steeredRight = true;       
+            orxout(user_info) << "Steering RIGHT "<<steering_.x << endl;
+        }else {
+            steeredRight = false;
+            steeredLeft = true;
+             orxout(user_info) << "Steering LEFT "<<steering_.x << endl;
+
+        }
+        
+
+        //lastTimeLeft = 0;
+        //desiredVelocity.x = value.x * speed;
     }
     void OrxyRoadShip::boost(bool bBoost)
     {
-        //getGame()->bEndGame = bBoost;
+        //bool boosting = bBoost;
     }
 
     inline bool OrxyRoadShip::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)

Modified: code/branches/OrxyRoad_FS18/src/modules/orxyroad/OrxyRoadShip.h
===================================================================
--- code/branches/OrxyRoad_FS18/src/modules/orxyroad/OrxyRoadShip.h	2018-04-26 13:21:23 UTC (rev 11907)
+++ code/branches/OrxyRoad_FS18/src/modules/orxyroad/OrxyRoadShip.h	2018-04-26 13:22:59 UTC (rev 11908)
@@ -73,6 +73,7 @@
 
             float speed, damping, posforeward;
             bool isFireing;
+            bool steeredLeft, steeredRight, forward, backward;
 
         protected:
             virtual void death() override;



More information about the Orxonox-commit mailing list