Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

I'm trying to understand, but much of this is going over my head.

I've tried copying your examples, but I'm not seeing anything happen in game.

What I've done is put this into a new plugin which sits below yours in the load order.

@template T 
@typedef {((
    this: ModifierDefinition,
    t: number,
    character: Game_CharacterBase,
) => T) & { [CONSTANT]?: T }} Varying
TS_Dynamic_Characters.parameters.modifierDefinitions.push(new TS_Dynamic_Characters.ModifierDefinition({
    name: 'bob-and-sway',
    bushDepth: 25, // This (by default) also turns on bush display for tile Events.
    anchorY: 50, // To rotate around the (vertical) centre, not the bottom.
    yOffsetVertical: function (t, { x, y }) {
        return -3 * t * Math.sin(phase(x, y) + Graphics.frameCount / 20);
    },
    angle: (t, { x, y }) => 5 * t * Math.sin(phase(x, y) + Graphics.frameCount / 15),
}));

I've kept the name for testing purposes and changed my character rule to look for bob-and-sway.

I'm not sure where I'm going wrong.

Thanks for all the help, and wishing you well.

(1 edit)

This part here:

@template T 
@typedef {((
    this: ModifierDefinition,
    t: number,
    character: Game_CharacterBase,
) => T) & { [CONSTANT]?: T }} Varying

is probably crashing the plugin when it loads, since it’s just a JSDoc comment (it’s used with other comments to enable type checks in the editor) but the part that makes it a comment is missing here as far as I can tell.

You can remove these lines entirely. The rest should then start working.

When I remove that part I get this error. Phase is not defined.

(TS_Dyn_WitchOrbHover is what I've put this stuff into.)


(2 edits)

I missed the first line(s) while copying, sorry. This should be fixed:

// This likely doesn't look great on moving Events!
const phase = (x, y) => (x * 147 + y * 15) % 11 / 5.5 * Math.PI;
TS_Dynamic_Characters.parameters.modifierDefinitions.push(new TS_Dynamic_Characters.ModifierDefinition({
	name: 'bob-and-sway',
	bushDepth: 25, // This (by default) also turns on bush display for tile Events.
	anchorY: 50, // To rotate around the (vertical) centre, not the bottom.

	// Note that using a custom function for any "offset" will turn off offset rounding by default!:

	yOffsetVertical: function (t, { x, y }) {
		// The second argument above is a `Game_CharacterBase` instance, which (among many more) has `x` and `y` properties.
		// `this`, here, is the `ModifierDefinition` instance.
		return -3 * t * Math.sin(phase(x, y) + Graphics.frameCount / 20);
	},

	// You can also write this more concisely, but without `this`:
	angle: (t, { x, y }) => 5 * t * Math.sin(phase(x, y) + Graphics.frameCount / 15),
}));

The phase formula is totally arbitrary, I just wrote something to make it different based on which tile the event sits on. You may want to use a formula that changes much more slowly in space (and also use { _realX: x, _realY: y } instead of { x, y } to get fractional numbers, but that can still look wrong on a looping map sometimes).

(+1)

That worked, thank you! I'll play with the formula from here to achieve the effect I'm going for.