So at the moment I am working on a 2D platformer and I have most of the game done but I need to add a boss. I have got the boss to work but one small problem…
One of his attacks is he throws a spike ball in the direction of the player but I have no idea how to make him do that. Can anybody help me?
// Clone the bullet as specified by the attribute
var bullet = this.Spike.clone();
// Add it to the game
this.app.root.addChild(bullet);
var Moss = this.entity;
var gun = this.Hand;
// Its force is in the direction the player is facing
this.force = new pc.Vec3();
this.force.copy(gun.forward);
this.force.scale(this.Speed);
var pos = gun.getPosition();
var direction = gun.forward;
// Add it a little further if the player is already going fast
// pos.add(direction.scale(5 + gun.rigidbody.linearVelocity.length() * 0.01));
bullet.setPosition( pos );
// try to get bullet to face forward
bullet.setLocalEulerAngles(0, 0, 0);
// var bulletRotation = player.getRotation();
// bullet.setRotation( bulletRotation );
// bullet.rotateLocal(90,0,0);
bullet.enabled = true; //Must enable after setting position!
bullet.rigidbody.applyImpulse(this.force);
setTimeout(function(){
bullet.destroy();
}, 4000);
This is what I have at the moment but the projectile just does nothing but spawn and dissapear.
That is the boss…
That little star-lookin thingy is the spike that needs to fly in the direction of the player.
If I don’t reply back right away it is because I am at school…
Help?
Hi @Connor_Briggs! As far as I can see, your code looks correct to me. Can you share your project please?
I sent you the link…
Your Spike entity has a kinematic rigidbody that doesn’t respond to forces. To solve this, you can change the rigidbody type to dynamic. However, you must make sure that this does not conflict with the rigidbody of the parent entity.
ok…
I’ll try that…
sorry was in science class
It worked kind of…
Great! You will probably need to make some other adjustments to get the desired result.
thanks so much for the help!