Crouching!

This commit is contained in:
2016-01-23 15:06:47 +01:00
parent b83d773627
commit 666ef6589e
5 changed files with 59 additions and 9 deletions
+2 -1
View File
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Player xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Player.xsd">
<MovementSpeed>0.2</MovementSpeed>
<MovementSpeed>3</MovementSpeed>
<CrouchSpeed>1.5</CrouchSpeed>
</Player>
+1
View File
@@ -10,6 +10,7 @@
<xs:complexType>
<xs:all>
<xs:element name="MovementSpeed" type="t:float" minOccurs="0"/>
<xs:element name="CrouchSpeed" type="t:float" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
@@ -13,6 +13,7 @@
<c:Model>
<Resource>Models/Core/UnitCube.obj</Resource>
<Color A="1" B="0.513725519" G="0" R="1"/>
<Visible>false</Visible>
</c:Model>
<c:Transform>
<Position X="7" Y="-0.727000058" Z="-1.22800004"/>
@@ -93,6 +94,7 @@
<c:Collidable/>
<c:Model>
<Resource>Models/Core/UnitCube.obj</Resource>
<Visible>false</Visible>
</c:Model>
<c:Transform>
<Position X="6.32800007" Y="0.807000041" Z="-2.2750001"/>
@@ -107,6 +109,7 @@
<c:Collidable/>
<c:Model>
<Resource>Models/Core/UnitCube.obj</Resource>
<Visible>false</Visible>
</c:Model>
<c:Transform>
<Position X="9.11900043" Y="0.5" Z="-2.10900021"/>
@@ -121,6 +124,7 @@
<c:Collidable/>
<c:Model>
<Resource>Models/Core/UnitCube.obj</Resource>
<Visible>false</Visible>
</c:Model>
<c:Transform>
<Position X="13.2370005" Y="1.28600001" Z="-1.71700013"/>
+33 -4
View File
@@ -7,6 +7,9 @@
<Size X="1" Y="1.60000002" Z="1"/>
</c:AABB>
<c:Collidable/>
<c:Model>
<Resource></Resource>
</c:Model>
<c:Physics/>
<c:Player>
<MovementSpeed>3</MovementSpeed>
@@ -17,7 +20,7 @@
</Team>
</c:Team>
<c:Transform>
<Position X="0" Y="0" Z="7.38143063"/>
<Position X="0" Y="0.0264999978" Z="7.38143063"/>
</c:Transform>
</Components>
@@ -27,19 +30,18 @@
<c:Camera/>
<c:Transform>
<Position X="0" Y="1.37700009" Z="0"/>
<Orientation X="6.28300047" Y="0" Z="0"/>
</c:Transform>
</Components>
<Children>
<Entity name="PlayerName">
<Components>
<c:Text>
<Content></Content>
<Resource>Fonts/DroidSans.ttf,100</Resource>
<Color A="1" B="0" G="1" R="0"/>
<Visible>false</Visible>
</c:Text>
<c:Transform>
<Position X="0" Y="0.0263664704" Z="-0.447885782"/>
<Position X="0" Y="0.247910097" Z="-0.447844714"/>
<Scale X="0.100000001" Y="0.113000005" Z="0.5"/>
<Orientation X="0" Y="3.14199996" Z="0"/>
</c:Transform>
@@ -85,6 +87,33 @@
</Components>
<Children/>
</Entity>
<Entity name="AABBStanding">
<Components>
<c:Model>
<Resource>Models/Core/UnitCube.obj</Resource>
<Color A="0.427450985" B="1" G="1" R="1"/>
<Visible>false</Visible>
</c:Model>
<c:Transform>
<Position X="0" Y="0.772000015" Z="0"/>
<Scale X="1" Y="1.60000002" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="AABBCrouching">
<Components>
<c:Model>
<Resource>Models/Core/UnitCube.obj</Resource>
<Color A="0.745098054" B="1" G="0" R="1"/>
<Visible>false</Visible>
</c:Model>
<c:Transform>
<Position X="0" Y="0.772000015" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
+19 -4
View File
@@ -37,12 +37,27 @@ void PlayerMovementSystem::Update(double dt)
ori.y += controller->Rotation().y;
glm::vec3& pos = cTransform["Position"];
pos += controller->Movement() * glm::inverse(glm::quat(ori)) * (float)player["Player"]["MovementSpeed"] * (float)dt;
float speed;
if (controller->Crouching()) {
speed = player["Player"]["CrouchSpeed"];
} else {
speed = player["Player"]["MovementSpeed"];
}
pos += controller->Movement() * glm::inverse(glm::quat(ori)) * speed * (float)dt;
if (player.HasComponent("Physics")) {
if (controller->Jumping()) {
glm::vec3& velocity = player["Physics"]["Velocity"];
velocity.y += 10.f;
glm::vec3& velocity = player["Physics"]["Velocity"];
if (controller->Jumping() && !controller->Crouching() && velocity.y == 0.f) {
velocity.y += 4.f;
}
}
if (player.HasComponent("AABB")) {
glm::vec3& size = player["AABB"]["Size"];
if (controller->Crouching()) {
size = glm::vec3(1.f, 1.f, 1.f);
} else {
size = glm::vec3(1.f, 1.6f, 1.f);
}
}