Fixing anim bugs, fixing car movement

This commit is contained in:
Vladislav Khorev 2018-09-23 16:53:57 +05:00
parent 582b9170db
commit d7f4b0c773
4 changed files with 68 additions and 33 deletions

11
ai.cpp
View File

@ -41,13 +41,20 @@ namespace OpenGTA {
//INFO << ped->rot + a << std::endl;
if (fabs(ped->rot - da) > 5) {
if (a > 0)
{
ped->m_control.setTurnLeft(true);
}
else
{
ped->m_control.setTurnRight(true);
}
if (fabs(ped->rot - da) < 120 && d > 0.19f)
}
if (fabs(ped->rot - da) < 120 && d > 0.25f)
{
ped->m_control.setMoveForward(true);
if (d <= 0.19f)
}
//if (d <= 0.19f)
if (d <= 0.25f)
{
ped->m_control.setTurnLeft(false);
ped->m_control.setTurnRight(false);

View File

@ -223,9 +223,14 @@ activeWeapon = chooseWeapon;
}
break;
case 0:
/*
if (!(animId == 1u + activeWeapon*3))
switchToAnim(1 + activeWeapon*3);*/
if (aimCarId == 0)
{
if (!(animId == 1u + activeWeapon * 3))
{
switchToAnim(1 + activeWeapon * 3);
}
}
break;
case -1:
if (!(animId == 2u + activeWeapon*3)) {
@ -735,6 +740,12 @@ activeWeapon = chooseWeapon;
//m_M.RotZ(rot+90);
CarSprite::update(ticks);
if (lastUpdateAt == 0) //skip first frame
{
lastUpdateAt = ticks;
return;
}
static const float velocityRotateK = 100.0;
@ -799,24 +810,36 @@ activeWeapon = chooseWeapon;
tryMove(pos + moveDelta);
/*
if (!inGroundContact) {
speedForces.y += 0.0005f *delta;
pos.y -= speedForces.y;
if (speedForces.y < 0.2f)
INFO << "bridge step? height: " << pos.y << " speed: " << speedForces.y << std::endl;
gravitySpeed += 0.0005f *delta;
pos.y -= gravitySpeed;
if (gravitySpeed < 0.2f)
INFO << "bridge step? height: " << pos.y << " speed: " << gravitySpeed << std::endl;
else
INFO << "FALLING " << pos.y << " speed " << speedForces.y << std::endl;
INFO << "FALLING " << pos.y << " speed " << gravitySpeed << std::endl;
}
else {
if (speedForces.y > 0.1)
INFO << "impacting with speed: " << speedForces.y << std::endl;
speedForces.y = 0.0f;
}*/
if (gravitySpeed > 0.1)
INFO << "impacting with speed: " << gravitySpeed << std::endl;
gravitySpeed = 0.0f;
}
m_M = TranslateMatrix3D(pos);
m_M.RotZ(rot);
if (id() == OpenGTA::LocalPlayer::Instance().playerCarId)
{
OpenGL::Camera & cam = OpenGL::CameraHolder::Instance();
static const float camVelocityK = 300.0;
cam.getEye().y = 10 + velocity*camVelocityK;
}
//INFO << pos.x << " " << pos.y << " " << pos.z << std::endl;*/
lastUpdateAt = ticks;
}
@ -830,28 +853,25 @@ activeWeapon = chooseWeapon;
OpenGTA::GraphicsBase & graphics = OpenGTA::StyleHolder::Instance().get();
int inGroundContact = 1;
//INFO << heightOverTerrain(nPos) << std::endl;
/*
float hot = heightOverTerrain(nPos);
if (hot > 0.3f)
{
inGroundContact = 0;
}
else if (hot < 0.0) {
WARN << "gone below: " << hot << " at " << nPos.x << ", " << nPos.y << ", " << nPos.z << std::endl;
nPos.y -= (hot - 0.3f);
//nPos.y += 1;
//INFO << nPos.y << std::endl;
inGroundContact = 1;
}
else {
inGroundContact = 1;
if (isDead)
nPos.y -= hot - 0.05f;
else
nPos.y -= hot - 0.1f;
}*/
}
if (y < map.getNumBlocksAtNew(PHYSFS_uint8(x), PHYSFS_uint8(z)) && y > 0.0f) {
@ -983,8 +1003,10 @@ activeWeapon = chooseWeapon;
obj_blocked = true;
}
}
if ((inGroundContact) && (obj_blocked == false))
if (/*(inGroundContact) && */(obj_blocked == false))
{
pos = nPos;
}
//else
// inGroundContact = 0;

View File

@ -154,7 +154,7 @@ namespace OpenGTA {
GraphicsBase::CarInfo & carInfo;
uint8_t type;
void update(Uint32 ticks);
Uint32 lastUpdateAt;
Uint32 lastUpdateAt = 0;
void damageAt(const Vector3D & hit, uint32_t dmg);
void explode();
@ -166,6 +166,8 @@ namespace OpenGTA {
Vector3D moveDelta = Vector3D(0, 0, 0);
//Vector3D velocity = Vector3D(0, 0, 0);
float velocity = 0;
float gravitySpeed = 0;
int inGroundContact = 0;
private:
void fixSpriteType();
int32_t hitPoints;

View File

@ -614,7 +614,7 @@ void create_car_at(const Vector3D v) {
//Car(const Vector3D & _pos, float _rot, uint32_t id, uint8_t _type, int16_t _remap = -1);
//OpenGTA::Car c2(Vector3D(7.25000000, 2.06562519, 90.2031250), 180, 999999, 18, 0);
OpenGTA::Car c2(Vector3D(v.x, 2.06562519, v.z), 180, 999999, 18, 0);
OpenGTA::Car c2(Vector3D(v.x, v.y, v.z), 180, 999999, 18, 0);
OpenGTA::SpriteManagerHolder::Instance().add(c2);
}
@ -947,6 +947,7 @@ void handleKeyPress( SDL_Keysym *keysym ) {
OpenGTA::Pedestrian & pped = OpenGTA::LocalPlayer::Instance().getPed();
pped.aiMode = 0;
pped.aimCarId = 0;
}
}
break;
@ -957,6 +958,7 @@ void handleKeyPress( SDL_Keysym *keysym ) {
{
OpenGTA::Pedestrian & pped = OpenGTA::LocalPlayer::Instance().getPed();
pped.aiMode = 0;
pped.aimCarId = 0;
}
}
break;
@ -967,6 +969,7 @@ void handleKeyPress( SDL_Keysym *keysym ) {
{
OpenGTA::Pedestrian & pped = OpenGTA::LocalPlayer::Instance().getPed();
pped.aiMode = 0;
pped.aimCarId = 0;
}
}
break;
@ -977,6 +980,7 @@ void handleKeyPress( SDL_Keysym *keysym ) {
{
OpenGTA::Pedestrian & pped = OpenGTA::LocalPlayer::Instance().getPed();
pped.aiMode = 0;
pped.aimCarId = 0;
}
}
break;