Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Harley

Hello all,

I have an issue where I'm trying to trigger an entity to move a certain distance, but I want to be able to set it's speed.

So for example I want it to move 300 pixels up at a speed of '10'. In an alternative scenario I want it to move 300 pixels up at a speed of '5'. I don't want to have to update it's position manually on every entity update() call - I just want to set it in motion and for the game update() to take care of it's movement until it reaches it's distance.

Currently I'm trying to do this with the vel.y. However because there is no distance component to velocity, if I lower the velocity it just moves less distance.

I'm sure I'm probably just overlooking a simple solution to this, but it would be great to get some help on this one.

Thanks,
Harley

1 decade ago by Harley

I think I've got it... I'll just set a "targetY" that the entity should be moving towards. Then on every entity update I'll just check if the entity has reached the targetY or not.

It's not ideal, because I have to manually check in every update, but it should work. If anyone knows a better way to do it, that would be great.

1 decade ago by Harley

No I don't think that's going to work, because then the gravity no longer works.

I found this formula:

velocity = distance / time.

So I can find my desired velocity by setting the distance I want to travel and how long it should take to travel there (at least I think that's how it works).

However the gravity screws this formula up and I don't know how to include the gravity in the formula.

1 decade ago by StuartTresadern

Hi, Have you tried just changing the accel.y also make sure that your maxVel: is set high enough.

1 decade ago by dominic

Instead of specifying beforehand how long the entity will travel, you could just check if it reached its goal already. If not, keep going.

update: function() {
	if( !reachedTargetPosition ) {
		this.vel.x = 0;
	}
	else {
		this.vel.x = speed;
	}

	this.parent();
}
Page 1 of 1
« first « previous next › last »