I need help with a few things
- I need Help with coding a jump
- I need help with coding a gun
- I need help with creating an explosion that can be called at will
Thanks for your time
Hope you get back to me soon
Sincerly
-William Boersma
I need help with a few things
Thanks for your time
Hope you get back to me soon
Sincerly
-William Boersma
Hi @WilliamBoersma31, and welcome!
For help with coding a jump mechanic, you can check out the following topic - How can I make my character jump?
For coding a gun, do you have your models ready, and you need help with coding the shooting bit of it? Do elaborate a bit more on what you have done, and what you need said gun to do.
For explosions, you can check out https://playcanvas.com/project/439297/overview/explosion-particle-effect, and check the play method
for particle systems - https://developer.playcanvas.com/en/api/pc.ParticleSystemComponent.html#play.
Hope this helps!
@DevilZ ok thank you also for 3 i meant more of launching things not particle although the particles will help
also for 1 i need help with ground check
For this, check if your character is colliding with the ground. Have a look at https://developer.playcanvas.com/en/tutorials/collision-and-triggers/
yes i have a code that used an entity with collision attatched to the ground but it did nothing when you pressed space
Jump.prototype.initialize = function() {
this.entity.collision.on(‘triggerenter’, this.onTriggerEnter, this);
};
// update code called every frame
Jump.prototype.onTriggerEnter = function(entity) {
entity.rigidbody.applyForce(0, 1, 0);
};
Also here is my other attempt at a jump
var position = this.entity.getPosition();
if (app.keyboard.isPressed(pc.KEY_SPACE)) {
if(this.groundedY) {
this.entity.rigidbody.applyImpulse(0, 0.5, 0);
}
}
if(position.y > 1.2) {
this.grounded = true;
}
else {
this.grounded = false;
}
So is this working? I don’t see why it shouldn’t, how did you arrive at the value 1.2? Although I don’t see you declare the variable groundedY, only grounded.
oh whoops ill fix that and try it thanks
@DevilZ I tried at and it didn’t work any thing else i need to fix?
var position = this.entity.getPosition();
if (app.keyboard.isPressed(pc.KEY_SPACE)) {
if(this.grounded) {
this.entity.rigidbody.applyImpulse(0, 0.5, 0);
}
}
if(position.y > 1.2) {
this.grounded = true;
}
else {
this.grounded = false;
}
};
What function is this under?
update
@DevilZ never mind about the jump i figured out a work around.
can you help me with making a gun that launches whatever you shoot?
also I’ve decide to scrap the explosion
Mainly raycasting help
I tried the raycasting tutorial but got confused
What exactly did you try? Any error messages? Please post the code here so we can have a look.
I figured out the raycasting i just need to find a way to shoot where im aiming
here is my code.
var Raycast = pc.createScript(‘powPow’);
// initialize code called once per entity
Raycast.prototype.initialize = function() {
if (!this.entity.camera) {
console.error(‘This script must be applied to an entity with a camera component.’);
return;
}
// Add a mousedown event handler
this.app.mouse.on(pc.EVENT_MOUSEDOWN, this.mouseDown, this);
// Add touch event only if touch is available
if (this.app.touch) {
this.app.touch.on(pc.EVENT_TOUCHSTART, this.touchStart, this);
}
};
Raycast.prototype.mouseDown = function (e) {
this.doRaycast(e.x, e.y);
};
Raycast.prototype.touchStart = function (e) {
// Only perform the raycast if there is one finger on the screen
if (e.touches.length === 1) {
this.doRaycast(e.touches[0].x, e.touches[0].y);
}
e.event.preventDefault();
};
Raycast.prototype.doRaycast = function (screenX, screenY) {
// The pc.Vec3 to raycast from (the position of the camera)
var from = this.entity.getPosition();
// The pc.Vec3 to raycast to (the click position projected onto the camera's far clip plane)
var to = this.entity.camera.screenToWorld(screenX, screenY, this.entity.camera.farClip);
// Raycast between the two points and return the closest hit result
var result = this.app.systems.rigidbody.raycastFirst(from, to);
// If there was a hit, store the entity
if (result) {
var entity = result.entity;
entity.rigidbody.applyImpulse(localOffset);
}
};