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

9 years ago by phi

I am having trouble with the spawn function in the TwoPointFive plugin.

There seems to be a slight offset and the object spawns a bit to the left/right and not in the center. This happens after the initial object is rotated.

ig.game.spawnEntity(EntityCorpse, this.pos.x, this.pos.y );

This should spawn a corpse sprite at the enemy position but it sometimes spawns with an offset left/right.

This is also present in the "Super Blob Blaster" demo with the grenade launcher shot (it does not matter there because the weapon sprite is quite big).
If you shoot at the beginning of the game the shot goes straight. If you rotate the player the shot is fired with an offset (depending on the direction).

9 years ago by Joncom

Maybe try spawning at the center of the entity:
var x = this.pos.x + this.size.x/2;
var y = this.pos.y + this.size.y/2;
ig.game.spawnEntity(EntityCorpse, x, y);

9 years ago by phi

Nope - that is not changing anything.
The spawning generally works but as soon as you rotate the player/entity everything gets messed up.

The method used in the Super Blob Blaster demo is:
ig.game.spawnEntity(EntityGrenade, x, y, {angle: angle} );

x =
this.pos.x+this.size.x/2 -Math.sin(this.angle) * 3;

y =
this.pos.y+this.size.y/2 -Math.cos(this.angle) * 3;

You can try it at http://phoboslab.org/twopointfive/
Just shoot and rotate to see the effect. The above code results in said effect.

/>			</div>
		</div>
			<div class=

9 years ago by fox1t

I saw the same problem. Good point. Xibalba however haven't this problem... So there is something wrong with the angle. I'll try to debug today/tomorrow to see whats going on. If you find something just update this thread.

9 years ago by fox1t

I can't find the code you posted. There is something similar on the line 83 84 in granade-launcher.js
this.vel.x = -Math.sin(this.angle) * this.speed;
this.vel.y = -Math.cos(this.angle) * this.speed;

9 years ago by phi

This is from the grenade-launcher.js (L 47)
shoot: function( x, y, angle ) {
ig.game.spawnEntity(EntityGrenade, x, y, {angle: angle} );

This is from the player.js (L 145/146)
// Calculate the spawn position for projectiles
var sx = this.pos.x+this.size.x/2 -Math.sin(this.angle) * 3;
sy = this.pos.y+this.size.y/2 -Math.cos(this.angle) * 3;

But I get the same effect (when the entity is rotated) using just
ig.game.spawnEntity(SomeEntity, this.pos.x, this.pos.y);

This is especially visible when spawning a corpse sprite at the exact same position the initial enemy sprite was. The corpse sprite is not moving so the rotation should not matter. The corpse sprite is sometimes spawned left/right of the enemy sprite.

9 years ago by fox1t

This is what i have in player.js on 144

		// Set the desired velocity based on our angle and which keys are
		// pressed
		this.vel.x = -Math.sin(this.angle) * dy * this.moveSpeed 
			-Math.sin(this.angle+Math.PI/2) * dx * this.moveSpeed;

		this.vel.y = -Math.cos(this.angle) * dy * this.moveSpeed 
			-Math.cos(this.angle+Math.PI/2) * dx * this.moveSpeed;

As you can see here https://github.com/phoboslab/TwoPointFive/blob/master/lib/game/entities/player.js#L144


And here is the line 47 from grenade-launcher.js
https://github.com/phoboslab/TwoPointFive/blob/master/lib/game/weapons/grenade-launcher.js#L47

9 years ago by Joncom

It seems like the bullet is not being spawned perfectly centered on the player.

Maybe this code:
x = this.pos.x+this.size.x/2 -Math.sin(this.angle) * 3;
y = this.pos.y+this.size.y/2 -Math.cos(this.angle) * 3;
ig.game.spawnEntity(EntityGrenade, x, y, {angle: angle} );

..should be updated:
x = this.pos.x+this.size.x/2 -Math.sin(this.angle) * 3 - EntityGrenade.prototype.size.x/2;
y = this.pos.y+this.size.y/2 -Math.cos(this.angle) * 3 - EntityGrenade.prototype.size.y/2;

9 years ago by fox1t

Quote from Joncom
It seems like the bullet is not being spawned perfectly centered on the player.

Maybe this code:
x = this.pos.x+this.size.x/2 -Math.sin(this.angle) * 3;
y = this.pos.y+this.size.y/2 -Math.cos(this.angle) * 3;
ig.game.spawnEntity(EntityGrenade, x, y, {angle: angle} );

..should be updated:
##
x = this.pos.x+this.size.x/2 -Math.sin(this.angle) * 3 - EntityGrenade.prototype.size.x/2;
y = this.pos.y+this.size.y/2 -Math.cos(this.angle) * 3 - EntityGrenade.prototype.size.y/2;
##


Just tested and it seems to fix the issue. Well done Joncom.
Page 1 of 1
« first « previous next › last »