Jump to content

Running, charging, stamina and stances (with a bit of formations)


Recommended Posts

15 hours ago, asterix said:

Look at the section formations https://trac.wildfiregames.com/wiki/Alpha23

Is says that the speed bonus is removed, is that what you are referring to? Because I tried to let units actually run in the formations (visualise an awesome cavalry charge) but, strangely, they only slow down when I try to use the run speed.

4 hours ago, (-_-) said:

What kind of information do you need from the hyrule code? (I talked to exo and while he did adapt it, the core concept remains the same)

Well, I don't *need* anything, but I'm just curious :) I wanted to see what code they used for the different steps, but if it is basically the same it is okay.

Link to post
Share on other sites
Formation.prototype.Run = function()
{
	let maxSpeed = 0;

	for (let ent of this.members)
	{
		let cmpUnitMotion = Engine.QueryInterface(ent, IID_UnitMotion);
		if (cmpUnitMotion) {
			if (maxSpeed == 0)
				maxSpeed = cmpUnitMotion.GetRunMultiplier();
			else
				maxSpeed = Math.min(maxSpeed, cmpUnitMotion.GetRunMultiplier());
		}
	}
	maxSpeed *= this.GetSpeedMultiplier(); <- apply formation speed multiplier

	this.speed = maxSpeed * this.minSpeed; <- this.minSpeed is minimal walking speed of formation
	this.running = true;

	let cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion);
	cmpUnitMotion.SetSpeedMultiplier(this.speed);
}

I use something like this

  • Like 1
  • Thanks 1
Link to post
Share on other sites
45 minutes ago, Angen said:

I use something like this

I changed the "ComputeMotionParameters" function to include a check whether "run" is called, to remove duplication ;) But that is not on SVN, so I probably need to use your code in the future :)

Link to post
Share on other sites
  • 2 months later...
On 5/20/2019 at 1:10 PM, Freagarach said:

I changed the "ComputeMotionParameters" function to include a check whether "run" is called, to remove duplication ;) But that is not on SVN, so I probably need to use your code in the future :)

Now is possible ? Or we need more pathfinder changes?

Link to post
Share on other sites
5 hours ago, Lion.Kanzen said:

Now is possible ? Or we need more pathfinder changes?

Well, my solution was neither regarding the pathfinder nor UnitMotion, it was regarding a function in Formation.js.

Spoiler

For reference this was my (currently hopelessly outdated) solution:


/**
 * Set formation controller's speed based on its current members.
 * @param {boolean} - whether the run-speed is wanted
 */
Formation.prototype.ComputeMotionParameters = function(run = false)
{
	let minSpeed = Infinity;

	for (let ent of this.members)
	{
		let cmpUnitMotion = Engine.QueryInterface(ent, IID_UnitMotion);
		if (cmpUnitMotion)
			minSpeed = run ? Math.min(minSpeed, cmpUnitMotion.GetRunSpeed()) : Math.min(minSpeed, cmpUnitMotion.GetWalkSpeed());
	}
	minSpeed *= this.GetSpeedMultiplier();

	let cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion);
	if (cmpUnitMotion)
		cmpUnitMotion.SetSpeed(minSpeed);
};

 

 

  • Like 1
Link to post
Share on other sites
  • 4 weeks later...
On 7/23/2019 at 12:36 AM, Freagarach said:

Well, my solution was neither regarding the pathfinder nor UnitMotion, it was regarding a function in Formation.js.

  Reveal hidden contents

For reference this was my (currently hopelessly outdated) solution:



/**
 * Set formation controller's speed based on its current members.
 * @param {boolean} - whether the run-speed is wanted
 */
Formation.prototype.ComputeMotionParameters = function(run = false)
{
	let minSpeed = Infinity;

	for (let ent of this.members)
	{
		let cmpUnitMotion = Engine.QueryInterface(ent, IID_UnitMotion);
		if (cmpUnitMotion)
			minSpeed = run ? Math.min(minSpeed, cmpUnitMotion.GetRunSpeed()) : Math.min(minSpeed, cmpUnitMotion.GetWalkSpeed());
	}
	minSpeed *= this.GetSpeedMultiplier();

	let cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion);
	if (cmpUnitMotion)
		cmpUnitMotion.SetSpeed(minSpeed);
};

 

 

But how will work for the user, a hotkeys or mouse command?

Link to post
Share on other sites
4 hours ago, Lion.Kanzen said:

But how will work for the user, a hotkeys or mouse command?

The way I implemented it was that at a certain (template-based) range from their targets, the units started running instead of walking. No user input required.

  • Like 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...