help please asap:"(( idk why my character seems like it’s getting pulled down by gravity. i’ve played with the mass of the rigid body and it still does not work. I’ve compared my codes to other people I know and although it’s almost copy&paste, it does not work like theirs>< here’s the link to my project: PlayCanvas 3D HTML5 Game Engine
Hi @SHERENATA_BURAHAN and welcome!
First of all, you need to remove the ;
sign on line 16, 25, 34 and 43 of your carlosMovement
script. You only use this sign to close a function. I think this is the main reason for the unexpected behavior.
Other than that, I only can find a ground entity that’s much lower than the character, so your character will fall down until it reach the collider.
By the way, your ‘borders’ setup is blocking the ability to select entities in the scene view.
how do you make it stay in place…??:"))
I’m not sure what kind of movement you’re looking for, but based on my assumption that it might be a “RPG MAKER” style, I’ll explain my approach accordingly.
First, set the physics Y-gravity to 0. *Gravity settings can be found in SETTINGS - PHYSICS
And then, Character Rigidbody value set like this:
Finally, you should change movement script code.
Use teleport
method instead of applyforce
method.
CarlosMovement.prototype.update = function(dt) {
const pos = this.entity.getPosition();
if(this.app.keyboard.isPressed(pc.KEY_RIGHT)){
this.entity.sprite.play('carlosWalkR');
// moves wacky to the right
this.entity.rigidbody.teleport(pos.x + 0.1, pos.y, pos.z);
}else if(this.app.keyboard.wasReleased(pc.KEY_RIGHT)){
// walk back to idle
this.entity.sprite.play('carlosIdle');
}
if(this.app.keyboard.isPressed(pc.KEY_LEFT)){
this.entity.sprite.play('carlosWalkL');
// moves wacky to the left
this.entity.rigidbody.teleport(pos.x - 0.1, pos.y, pos.z);
}else if(this.app.keyboard.wasReleased(pc.KEY_LEFT)){
// walk back to idle
this.entity.sprite.play('carlosIdle');
}
if(this.app.keyboard.isPressed(pc.KEY_UP)){
this.entity.sprite.play('carlosWalkU');
// moves wacky forward
this.entity.rigidbody.teleport(pos.x, pos.y + 0.1, pos.z);
}else if(this.app.keyboard.wasReleased(pc.KEY_UP)){
// walk back to idle
this.entity.sprite.play('carlosIdle');
}
if(this.app.keyboard.isPressed(pc.KEY_DOWN)){
this.entity.sprite.play('carlosWalkD');
// moves froggie downward
this.entity.rigidbody.teleport(pos.x ,pos.y - 0.1, pos.z);
}else if(this.app.keyboard.wasReleased(pc.KEY_DOWN)){
// walk back to idle
this.entity.sprite.play('carlosIdle');
}
};
it finally worked!! thank you so much T0T!!! you saved my final project for school T0T