Compare commits
2 Commits
d3848169e8
...
cfe84f1438
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cfe84f1438 | ||
|
|
dbe2e0da8e |
@ -37,9 +37,8 @@ void game::Character::Update()
|
|||||||
Super::Update();
|
Super::Update();
|
||||||
|
|
||||||
SyncTransformFromController();
|
SyncTransformFromController();
|
||||||
root_.UpdateMatrix();
|
|
||||||
|
|
||||||
UpdateMovement();
|
UpdateMovement();
|
||||||
|
root_.UpdateMatrix();
|
||||||
|
|
||||||
sync_current_ = 1 - sync_current_;
|
sync_current_ = 1 - sync_current_;
|
||||||
UpdateSyncState();
|
UpdateSyncState();
|
||||||
@ -147,22 +146,21 @@ void game::Character::SyncTransformFromController()
|
|||||||
void game::Character::UpdateMovement()
|
void game::Character::UpdateMovement()
|
||||||
{
|
{
|
||||||
constexpr float dt = 1.0f / 25.0f;
|
constexpr float dt = 1.0f / 25.0f;
|
||||||
constexpr float running_mult = 3.0f;
|
|
||||||
bool walking = false;
|
bool walking = false;
|
||||||
bool running = false;
|
bool running = false;
|
||||||
glm::vec2 movedir(0.0f);
|
glm::vec2 movedir(0.0f);
|
||||||
|
|
||||||
if (in_ & (1 << CIN_FORWARD))
|
if (in_ & (1 << CIN_FORWARD))
|
||||||
movedir.x += 1.0f;
|
movedir.y += 1.0f;
|
||||||
|
|
||||||
if (in_ & (1 << CIN_BACKWARD))
|
if (in_ & (1 << CIN_BACKWARD))
|
||||||
movedir.x -= 1.0f;
|
|
||||||
|
|
||||||
if (in_ & (1 << CIN_RIGHT))
|
|
||||||
movedir.y -= 1.0f;
|
movedir.y -= 1.0f;
|
||||||
|
|
||||||
|
if (in_ & (1 << CIN_RIGHT))
|
||||||
|
movedir.x -= 1.0f;
|
||||||
|
|
||||||
if (in_ & (1 << CIN_LEFT))
|
if (in_ & (1 << CIN_LEFT))
|
||||||
movedir.y += 1.0f;
|
movedir.x += 1.0f;
|
||||||
|
|
||||||
glm::vec3 walkdir(0.0f);
|
glm::vec3 walkdir(0.0f);
|
||||||
|
|
||||||
@ -173,17 +171,19 @@ void game::Character::UpdateMovement()
|
|||||||
if (in_ & (1 << CIN_SPRINT))
|
if (in_ & (1 << CIN_SPRINT))
|
||||||
running = true;
|
running = true;
|
||||||
|
|
||||||
float target_yaw = forward_yaw_ + std::atan2(movedir.y, movedir.x);
|
float target_yaw = forward_yaw_ + std::atan2(movedir.x, movedir.y);
|
||||||
Turn(yaw_, target_yaw, 8.0f * dt);
|
Turn(yaw_, target_yaw, turn_speed_ * dt);
|
||||||
|
|
||||||
glm::vec3 forward_dir(glm::cos(yaw_), glm::sin(yaw_), 0.0f);
|
glm::vec3 forward_dir(-glm::sin(yaw_), glm::cos(yaw_), 0.0f);
|
||||||
walkdir = forward_dir * walk_speed_ * dt;
|
walkdir = forward_dir * walk_speed_ * dt;
|
||||||
|
|
||||||
if (running)
|
if (running)
|
||||||
walkdir *= running_mult;
|
walkdir *= run_speed_mult_;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
root_.local.rotation = glm::angleAxis(yaw_, glm::vec3(0.0f, 0.0f, 1.0f));
|
||||||
|
|
||||||
if (controller_)
|
if (controller_)
|
||||||
{
|
{
|
||||||
auto& bt_character = controller_->GetBtController();
|
auto& bt_character = controller_->GetBtController();
|
||||||
@ -200,7 +200,7 @@ void game::Character::UpdateMovement()
|
|||||||
MoveToward(animstate_.loco_blend, run_blend_target, dt * 2.0f);
|
MoveToward(animstate_.loco_blend, run_blend_target, dt * 2.0f);
|
||||||
float anim_speed = glm::mix(0.5f, 1.5f, UnMix(0.0f, 0.5f, animstate_.loco_blend));
|
float anim_speed = glm::mix(0.5f, 1.5f, UnMix(0.0f, 0.5f, animstate_.loco_blend));
|
||||||
if (running)
|
if (running)
|
||||||
anim_speed *= running_mult;
|
anim_speed *= run_speed_mult_;
|
||||||
animstate_.loco_phase = glm::mod(animstate_.loco_phase + anim_speed * dt, 1.0f);
|
animstate_.loco_phase = glm::mod(animstate_.loco_phase + anim_speed * dt, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -71,12 +71,14 @@ public:
|
|||||||
|
|
||||||
void SetPosition(const glm::vec3& position);
|
void SetPosition(const glm::vec3& position);
|
||||||
|
|
||||||
|
|
||||||
|
~Character() override = default;
|
||||||
|
|
||||||
|
protected:
|
||||||
void SetIdleAnim(const std::string& anim_name);
|
void SetIdleAnim(const std::string& anim_name);
|
||||||
void SetWalkAnim(const std::string& anim_name);
|
void SetWalkAnim(const std::string& anim_name);
|
||||||
void SetRunAnim(const std::string& anim_name);
|
void SetRunAnim(const std::string& anim_name);
|
||||||
|
|
||||||
~Character() override = default;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void SyncControllerTransform();
|
void SyncControllerTransform();
|
||||||
void SyncTransformFromController();
|
void SyncTransformFromController();
|
||||||
@ -88,6 +90,11 @@ private:
|
|||||||
|
|
||||||
assets::AnimIdx GetAnim(const std::string& name) const;
|
assets::AnimIdx GetAnim(const std::string& name) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
float turn_speed_ = 8.0f;
|
||||||
|
float walk_speed_ = 2.0f;
|
||||||
|
float run_speed_mult_ = 3.0f;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CharacterTuning tuning_;
|
CharacterTuning tuning_;
|
||||||
|
|
||||||
@ -103,8 +110,6 @@ private:
|
|||||||
float yaw_ = 0.0f;
|
float yaw_ = 0.0f;
|
||||||
float forward_yaw_ = 0.0f;
|
float forward_yaw_ = 0.0f;
|
||||||
|
|
||||||
float walk_speed_ = 2.0f;
|
|
||||||
|
|
||||||
SkeletonInstance sk_;
|
SkeletonInstance sk_;
|
||||||
CharacterAnimState animstate_;
|
CharacterAnimState animstate_;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
#include "cow.hpp"
|
#include "cow.hpp"
|
||||||
|
#include "utils/random.hpp"
|
||||||
|
|
||||||
static game::CharacterTuning GetCowTuning()
|
static game::CharacterTuning GetCowTuning()
|
||||||
{
|
{
|
||||||
@ -10,11 +11,61 @@ static game::CharacterTuning GetCowTuning()
|
|||||||
|
|
||||||
game::Cow::Cow(World& world, const glm::vec3& position, float yaw) : Animal(world, GetCowTuning(), position, yaw)
|
game::Cow::Cow(World& world, const glm::vec3& position, float yaw) : Animal(world, GetCowTuning(), position, yaw)
|
||||||
{
|
{
|
||||||
|
walk_speed_ = 3.0f;
|
||||||
|
turn_speed_ = 3.0f;
|
||||||
|
|
||||||
SetUseMessage("vlízt na krávu");
|
SetUseMessage("vlízt na krávu");
|
||||||
|
|
||||||
AddAnimalSeat(glm::vec3(0.0f, -0.098926f, 0.447576f));
|
AddAnimalSeat(glm::vec3(0.0f, 0.098926f, 0.447576f));
|
||||||
AddAnimalSeat(glm::vec3(0.0f, 0.394027f, 0.458536f));
|
AddAnimalSeat(glm::vec3(0.0f, -0.394027f, 0.458536f));
|
||||||
|
|
||||||
SetIdleAnim("idle");
|
SetIdleAnim("idle");
|
||||||
SetWalkAnim("walk");
|
SetWalkAnim("walk");
|
||||||
|
|
||||||
|
ScheduleRandomMoo();
|
||||||
|
}
|
||||||
|
|
||||||
|
void game::Cow::OnPassengerChanged(size_t seat_idx, HumanCharacter* passenger)
|
||||||
|
{
|
||||||
|
Super::OnPassengerChanged(seat_idx, passenger);
|
||||||
|
|
||||||
|
if (passenger)
|
||||||
|
{
|
||||||
|
PlayUseSound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void game::Cow::ScheduleRandomMoo()
|
||||||
|
{
|
||||||
|
Schedule(rand() % 15000 + 5000, [this]() {
|
||||||
|
PlayRandomMoo();
|
||||||
|
ScheduleRandomMoo();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void game::Cow::PlayRandomMoo()
|
||||||
|
{
|
||||||
|
float volume = RandomFloat(0.9f, 1.1f);
|
||||||
|
float pitch = RandomFloat(0.9f, 1.0f);
|
||||||
|
|
||||||
|
switch (rand() % 4)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
PlaySound("cow-01", volume, pitch);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
PlaySound("cow-02", volume, pitch);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
PlaySound("cow-04", volume, pitch);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
PlaySound("cow-05", volume, pitch);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void game::Cow::PlayUseSound()
|
||||||
|
{
|
||||||
|
PlaySound("cow-06", 1.0f, RandomFloat(0.9f, 1.1f));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,10 +8,17 @@ namespace game
|
|||||||
class Cow : public Animal
|
class Cow : public Animal
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
using Super = Animal;
|
||||||
|
|
||||||
Cow(World& world, const glm::vec3& position, float yaw);
|
Cow(World& world, const glm::vec3& position, float yaw);
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
|
virtual void OnPassengerChanged(size_t seat_idx, HumanCharacter* passenger) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void ScheduleRandomMoo();
|
||||||
|
void PlayRandomMoo();
|
||||||
|
void PlayUseSound();
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -29,7 +29,7 @@ void game::HumanCharacter::SetRideable(Rideable* rideable, size_t seat_idx)
|
|||||||
|
|
||||||
Attach(rideable->GetEntity().GetEntNum());
|
Attach(rideable->GetEntity().GetEntNum());
|
||||||
SetIdleAnim((rideable->GetRideableType() == RIDEABLE_VEHICLE && seat_idx == 0) ? "vehicle_drive" : "vehicle_passenger");
|
SetIdleAnim((rideable->GetRideableType() == RIDEABLE_VEHICLE && seat_idx == 0) ? "vehicle_drive" : "vehicle_passenger");
|
||||||
SetYaw(rideable->GetRideableType() == RIDEABLE_VEHICLE ? 0.5f * glm::pi<float>() : 1.0f * glm::pi<float>());
|
SetYaw(0.0f);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -180,8 +180,8 @@ bool game::view::CharacterView::ReadState(net::InMessage* msg)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
net::DecodePosition(sync_.pos, new_state.trans.position);
|
net::DecodePosition(sync_.pos, new_state.trans.position);
|
||||||
new_state.trans.rotation = glm::rotate(glm::quat(1.0f, 0.0f, 0.0f, 0.0f),
|
new_state.trans.rotation =
|
||||||
sync_.yaw.Decode() + glm::pi<float>() * 0.5f, glm::vec3(0, 0, 1));
|
glm::rotate(glm::quat(1.0f, 0.0f, 0.0f, 0.0f), sync_.yaw.Decode(), glm::vec3(0, 0, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fields & CSF_IDLE_ANIM)
|
if (fields & CSF_IDLE_ANIM)
|
||||||
|
|||||||
@ -131,7 +131,7 @@ void game::view::ClientSession::GetViewInfo(glm::vec3& eye, glm::mat4& view) con
|
|||||||
float yaw_sin = glm::sin(yaw_);
|
float yaw_sin = glm::sin(yaw_);
|
||||||
float pitch_cos = glm::cos(pitch_);
|
float pitch_cos = glm::cos(pitch_);
|
||||||
float pitch_sin = glm::sin(pitch_);
|
float pitch_sin = glm::sin(pitch_);
|
||||||
glm::vec3 dir(yaw_cos * pitch_cos, yaw_sin * pitch_cos, pitch_sin);
|
glm::vec3 dir(-yaw_sin * pitch_cos, yaw_cos * pitch_cos, pitch_sin);
|
||||||
|
|
||||||
glm::vec3 end = start - dir * distance;
|
glm::vec3 end = start - dir * distance;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user