otclient icon indicating copy to clipboard operation
otclient copied to clipboard

Monster dash

Open yuriouverney opened this issue 8 years ago • 10 comments

Monsters appear to be dashing when approaching the target, check recording: https://i.gyazo.com/276e94b77add6042f7c0d1663645bb64.mp4 This appear only on OTClient. When pushing a creature around me they move smoothly, NPCs also have fine movement.

When pushing a creature diagonally they lag, check recording: https://i.gyazo.com/412d93e4a799cdc93fd098c04001d7e2.mp4 This only OTClient (using 7.4 spr)

Is there a quickfix for this?

I using OTX3. (7.72)

yuriouverney avatar Jan 18 '18 02:01 yuriouverney

This reproduce inclusive on tfs 1.3 - 10.99

mattyx14 avatar Jan 18 '18 03:01 mattyx14

fix?

EmersonHenriique avatar Jun 26 '18 00:06 EmersonHenriique

@mattyx14

EmersonHenriique avatar Jun 28 '18 23:06 EmersonHenriique

Why closed?

GustavoContreiras avatar Feb 26 '19 21:02 GustavoContreiras

Let me give you a hint, this is connected to Creature::updateWalkAnimation. It works like a clockwork, you should find the right formula, it's basically trial and error or check the decompiled flash for the code and find out ;)

Best Wishes, Okke

okk3 avatar Feb 27 '19 08:02 okk3

I fixed the player walk animation in this function, it's almost like real tibia, but don't know what to do to fix monsters animation/dash

void Creature::updateWalkAnimation(int totalPixelsWalked)
{
    // update outfit animation
    if(m_outfit.getCategory() != ThingCategoryCreature)
        return;

    int footAnimPhases = getAnimationPhases() - 1; //returns 8 for player
    float footDelay = getStepDuration(true) / footAnimPhases; //varies with the ground

    // since mount is a different outfit we need to get the mount animation phases
    if(m_outfit.getMount() != 0) {
        ThingType *type = g_things.rawGetThingType(m_outfit.getMount(), m_outfit.getCategory());
        footAnimPhases = type->getAnimationPhases() - 1;
		footDelay = getStepDuration(true) / footAnimPhases;
    }

	if (totalPixelsWalked >= 32 && !m_walkFinishAnimEvent) {
		m_footStep = 0; //

		auto self = static_self_cast<Creature>();
		m_walkFinishAnimEvent = g_dispatcher.scheduleEvent([self] {
			if (!self->m_walking || self->m_walkTimer.ticksElapsed() >= self->getStepDuration(true)) {
				self->m_walkAnimationPhase = 0;
			}
			self->m_walkFinishAnimEvent = nullptr;
		}, std::min<int>(footDelay, 200));
	}

	if (footAnimPhases == 0) {
		m_walkAnimationPhase = 0;
	}
    else if(m_footStepDrawn && m_footTimer.ticksElapsed() >= footDelay && totalPixelsWalked < 32) {
        m_footStep++;
		m_walkAnimationPhase = (m_footStep % footAnimPhases);
        m_footStepDrawn = false;
        m_footTimer.restart();
    }
	else if(m_walkAnimationPhase == 0 && totalPixelsWalked < 32) {
		m_walkAnimationPhase = (m_footStep % footAnimPhases);
    }
}

GustavoContreiras avatar Feb 28 '19 13:02 GustavoContreiras

Thanks for the contribution, Gustavo.

The next hint for the animation / dash part: check speed factor on the function Creature::getStepDuration.

Best WIshes, Okke

okk3 avatar Feb 28 '19 14:02 okk3

Factor is only used for diagonal movements, setting it to 1 or 1.5f solves the laggy diagonal issue on 10.98 / TFS 1.3. Thanks for the tip!

But the dashing problem is the most annoying and I still don't know how to fix

GustavoContreiras avatar Feb 28 '19 14:02 GustavoContreiras

Players that click on map also look like dashing.

My guess is that this is a problem drawing things that aren't the local player. Maybe client is receiving these packets wrong or delayed, I dont know...

Edit: maybe around here, in tile.cpp:

// creatures
    if(drawFlags & Otc::DrawCreatures) {
        if(animate) {
            for(const CreaturePtr& creature : m_walkingCreatures) {
                creature->draw(Point(dest.x + ((creature->getPosition().x - m_position.x)*Otc::TILE_PIXELS - m_drawElevation)*scaleFactor,
                                     dest.y + ((creature->getPosition().y - m_position.y)*Otc::TILE_PIXELS - m_drawElevation)*scaleFactor), scaleFactor, animate, lightView);
            }
        }

        for(auto it = m_things.rbegin(); it != m_things.rend(); ++it) {
            const ThingPtr& thing = *it;
            if(!thing->isCreature())
                continue;
            CreaturePtr creature = thing->static_self_cast<Creature>();
            if(creature && (!creature->isWalking() || !animate))
                creature->draw(dest - m_drawElevation*scaleFactor, scaleFactor, animate, lightView);
        }
    }

GustavoContreiras avatar Mar 01 '19 19:03 GustavoContreiras

Made a super slow motion to show the exaclty dashing issue: https://streamable.com/2xek1 going from up to down and comparing with real gif and sprites https://streamable.com/wmv6e going from right to left https://ezgif.com/split/ezgif-1-1c80fb2cf982.gif gif and sprites

I really wanna fix this, does anyone have any tips?

GustavoContreiras avatar Mar 02 '19 14:03 GustavoContreiras