[SOLVED] Query about FOLLOW_EXACTLY

Started by shaun9991, Sun 06/02/2022 13:30:50

Previous topic - Next topic

shaun9991

Hi there!

Is there any way I can have a character follow another character EXACTLY, but with an amended y value? I want to introduce character shadows but I've drawn all my characters sprites in a way that their feet touch the very bottom of the sprite canvas. So I need the shadows to be sort of following Ego exactly, but with like y+10 to ensure the shadow is placed properly. I hope that makes sense!

Any help super appreciated :)

Best wishes,
Shaun
Support Cloak and Dagger Games on Patreon: https://www.patreon.com/user?u=460039

Crimson Wizard

If it's only the vertical offset, you may use Character.z property to assign a visual offset by Y axis. This way you may still use FollowCharacter function.


If above does not work for any reason, or the offset is more complicated, the solution is to instead assign shadow's position yourself in "late_repeatedly_execute_always", as this function is called right after the game update (but before the game redraw).

Code: ags

function late_repeatedly_execute_always()
{
    cShadow.x = cEgo.x + shadow_offsetx;
    cShadow.y = cEgo.y + shadow_offsety;
}

shaun9991

Thanks so much CW :)

The late_repeatedly_execute_always function you suggested works perfectly.

Though I've noticed that the shadow doesn't scale on walkable areas which have variable scaling levels. UseRoomAreaScaling is set to True for the shadow character. Am I missing something straight forward here do you think?

Many thanks,
Shaun
Support Cloak and Dagger Games on Patreon: https://www.patreon.com/user?u=460039

Crimson Wizard

Quote from: shaun9991 on Sun 06/02/2022 13:59:59
Though I've noticed that the shadow doesn't scale on walkable areas which have variable scaling levels. UseRoomAreaScaling is set to True for the shadow character. Am I missing something straight forward here do you think?

Well, if you modify it's position, it may get outside the walkable area. In this case you might turn UseRoomAreaScaling off and additionally set its scaling to match the character:
Code: ags

cShadow.Scaling = cEgo.Scaling;

shaun9991

#4
Thanks CW! That worked :)

One (hopefully :)) final question... as Ego walks up/down the screen and the scaling changes, the shadow sort of drifts away/drifts back again. Example below

At normal standard default scaling, all good:


Ego scaled down:


I'm guessing this might have something to do with the  late_repeatedly_execute_always function?

Many thanks,
Shaun
Support Cloak and Dagger Games on Patreon: https://www.patreon.com/user?u=460039

Crimson Wizard

#5
Quote from: shaun9991 on Sun 06/02/2022 14:19:02
as Ego walks up/down the screen and the scaling changes, the shadow sort of drifts away/drifts back again. Example below

I think this happens because character scales, and shadow scales, but distance between them remains the same absolute number. So you also need to scale the distance (offset).
Something like
Code: ags

function late_repeatedly_execute_always()
{
    cShadow.Scaling = cEgo.Scaling;
    cShadow.x = cEgo.x + (cShadow.Scaling * shadow_offsetx) / 100;
    cShadow.y = cEgo.y + (cShadow.Scaling * shadow_offsety) / 100;
}

shaun9991

Thanks so much CW, this works perfectly. This has saved me a week of pulling my hair out, I really appreciate it :)
Support Cloak and Dagger Games on Patreon: https://www.patreon.com/user?u=460039

SMF spam blocked by CleanTalk