Index: code/branches/OrxoBlox_FS19/src/modules/weapons/projectiles/BallProjectile.cc
===================================================================
--- code/branches/OrxoBlox_FS19/src/modules/weapons/projectiles/BallProjectile.cc	(revision 12291)
+++ code/branches/OrxoBlox_FS19/src/modules/weapons/projectiles/BallProjectile.cc	(revision 12310)
@@ -40,4 +40,6 @@
 #include "core/command/Executor.h"
 #include "util/Convert.h"
+#include <bullet/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h>
+#include <bullet/LinearMath/btVector3.h>
 
 namespace orxonox
@@ -58,5 +60,8 @@
     void BallProjectile::registerVariables()
     {
+        registerVariable( this->fieldWidth_ );
+        registerVariable( this->fieldHeight_ );
         registerVariable(this->materialBase_);
+        registerVariable( this->speed_ );
     }
 
@@ -87,9 +92,11 @@
     }
 
+
+
     void BallProjectile::Bounce(WorldEntity* otherObject, btManifoldPoint& contactPoint, const btCollisionShape* cs) {
 
         Vector3 velocity = this->getVelocity();
-        Vector3 positionOtherObject = otherObject->getPosition();
-        Vector3 contactPosition = this->getPosition();
+        Vector3 myPosition = otherObject->getPosition();
+        btVector3 positionOtherObject = contactPoint.getPositionWorldOnA();
         orxout() << "About to Bounce >D" << endl;
         //if (positionOtherObject.y < 0) {
@@ -98,40 +105,37 @@
         //else {
         
-            int distance_X = positionOtherObject.x - contactPosition.x;
-            int distance_Y = positionOtherObject.y - contactPosition.y;
+            int distance_X = positionOtherObject.getX() - myPosition.x;
+            int distance_Z = positionOtherObject.getZ() - myPosition.z;
 
             if (distance_X < 0)
-                distance_Y = -distance_Y;
+                distance_X = -distance_X;
     
 
-            if (distance_Y < 0)
-                distance_X = -distance_X;
-
-            if (distance_X < distance_Y)
-                velocity.y = -velocity.y;
-            if (distance_Y < distance_X)
+            if (distance_Z < 0)
+                distance_Z = -distance_Z;
+
+            orxout() << distance_X << endl;
+            orxout() << distance_Z << endl;
+
+            if (distance_X < distance_Z) {
+                velocity.z = -velocity.z;
+                orxout() << "z" << endl;
+            }
+            if (distance_Z < distance_X) {
                 velocity.x = -velocity.x;
+                orxout() << "x" << endl;
+            }
             else {
                 velocity.x = -velocity.x;
-                velocity.y = -velocity.y;
+                velocity.z = -velocity.z;
+                orxout() << "both" << endl;
             }
+            this->setVelocity(velocity);
         //}
     }
 
-/**
-    @brief
-        The function called when a projectile hits another thing.
-        Calls the hit-function, starts the shield recharge countdown, displays visual hit effects defined in Pawn.
-        Needs to be called in the collidesAgainst() function by every Class directly inheriting from BasicProjectile.
-    @param otherObject
-        A pointer to the object the Projectile has collided against.
-    @param contactPoint
-        A btManifoldPoint indicating the point of contact/impact.
-    @param cs
-        The btCollisionShape of the other object
-    @return
-        Returns true if the collision resulted in a successful hit.
-    @see Pawn.h
-    */
+
+
+
     
     bool BallProjectile::processCollision(WorldEntity* otherObject, btManifoldPoint& contactPoint, const btCollisionShape* cs)
@@ -145,3 +149,87 @@
         return result;
     }
+
+
+
+
+
+
+    void BallProjectile::tick(float dt)
+    {
+        SUPER(BallProjectile, tick, dt);
+
+        // Get the current position, velocity and acceleration of the ball.
+        Vector3 position = this->getPosition();
+        Vector3 velocity = this->getVelocity();
+        Vector3 acceleration = this->getAcceleration();
+
+        // If the ball has gone over the top or bottom boundary of the playing field (i.e. the ball has hit the top or bottom delimiters).
+        if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2)
+        {
+            // Its velocity in z-direction is inverted (i.e. it bounces off).
+            velocity.z = -velocity.z;
+            // And its position is set as to not overstep the boundary it has just crossed.
+            if (position.z > this->fieldHeight_ / 2)
+                position.z = this->fieldHeight_ / 2;
+            if (position.z < -this->fieldHeight_ / 2)
+                position.z = -this->fieldHeight_ / 2;
+
+            this->fireEvent();
+        }
+        
+        //Ball hits the right or left wall and should bounce back.
+        // If the ball has crossed the left or right boundary of the playing field.
+        if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2)
+        {
+            //Ball hits the right Wall
+            if (position.x > this->fieldWidth_ / 2)
+                {
+                    // Set the ball to be exactly at the boundary.
+                    position.x = this->fieldWidth_ / 2;
+                    // Invert its velocity in x-direction (i.e. it bounces off).
+                    velocity.x = -velocity.x;
+                    this->fireEvent();
+                    }
+
+            //Ball hits the left wall
+            else if (position.x < -this->fieldWidth_ / 2)
+                {
+                        // Set the ball to be exactly at the boundary.
+                        position.x = -this->fieldWidth_ / 2;
+                        // Invert its velocity in x-direction (i.e. it bounces off).
+                        velocity.x = -velocity.x;
+                        this->fireEvent();
+                    }
+        }
+
+        // Set the position, velocity and acceleration of the ball, if they have changed.
+        if (acceleration != this->getAcceleration())
+            this->setAcceleration(acceleration);
+        if (velocity != this->getVelocity())
+            this->setVelocity(velocity);
+        if (position != this->getPosition())
+            this->setPosition(position);
+    }
+
+
+
+
+    void BallProjectile::setSpeed(float speed)
+    {
+        if (speed != this->speed_) // If the speed changes
+        {
+            this->speed_ = speed;
+
+            // Set the speed in the direction of the balls current velocity.
+            Vector3 velocity = this->getVelocity();
+            if (velocity.x != 0)
+                velocity.x = sgn(velocity.x) * this->speed_;
+            else // If the balls current velocity is zero, the speed is set in a random direction.
+                velocity.x = this->speed_ * sgn(rnd(-1,1));
+
+            this->setVelocity(velocity);
+        }
+    }
+
+
 }
Index: code/branches/OrxoBlox_FS19/src/modules/weapons/projectiles/BallProjectile.h
===================================================================
--- code/branches/OrxoBlox_FS19/src/modules/weapons/projectiles/BallProjectile.h	(revision 12291)
+++ code/branches/OrxoBlox_FS19/src/modules/weapons/projectiles/BallProjectile.h	(revision 12310)
@@ -54,4 +54,7 @@
             void Bounce(WorldEntity* otherObject, btManifoldPoint& contactPoint, const btCollisionShape* cs);
             virtual void setMaterial(const std::string& material) override;
+            virtual void tick(float dt) override;
+            void setSpeed(float speed);
+
 
         protected:
@@ -63,4 +66,7 @@
             void changeTexture();
             
+            float speed_; //!< The speed (in x-direction) of the ball.
+            float fieldWidth_; //!< The width of the playing field.
+            float fieldHeight_; //!< The height of the playing field.
             unsigned int textureIndex_; //!< The current index of the texture. (i.e. the index of the currently displayed texture)
             unsigned int maxTextureIndex_; //!< The maximal index.
