Help with dialogue, i got some code for dialogue and it will only show the old code,
heres the link
https://playcanvas.com/project/1136429/overview/blank-project
Help with dialogue, i got some code for dialogue and it will only show the old code,
heres the link
https://playcanvas.com/project/1136429/overview/blank-project
you initialized the silly script two times, remove all the code from sillyScript and add this
var SillyScript = pc.createScript('sillyScript');
// initialize code called once per entity
SillyScript.prototype.initialize = function() {
// Get the rigid body component
this.rigidBody = this.entity.rigidbody;
};
// update code called every frame
SillyScript.prototype.update = function(dt) {
// Use forces to move the entity based on keyboard input
var force = new pc.Vec3();
if (this.app.keyboard.isPressed(pc.KEY_W)) {
force.y += 1;
}
if (this.app.keyboard.isPressed(pc.KEY_S)) {
force.y -= 1;
}
if (this.app.keyboard.isPressed(pc.KEY_A)) {
force.x -= 1;
}
if (this.app.keyboard.isPressed(pc.KEY_D)) {
force.x += 1;
}
// Normalize the force vector to ensure consistent movement speed
force.normalize().scale(10); // Adjust the scale factor to control movement speed
// Apply the force to the rigid body
this.rigidBody.applyForce(force);
// Set the sprite animation based on the input
if (force.lengthSq() > 1) {
this.entity.sprite.play("sillyMoving");
} else {
this.entity.sprite.play("sillyIdle");
}
};
hello, this is a new account, and it doesn’t let me move,
im not sure how to fix it
so, i was making dialogue and i put in this code
var SillyScript = pc.createScript('sillyScript');
// initialize code called once per entity
SillyScript.prototype.initialize = function() {
// Get the rigid body component
this.rigidBody = this.entity.rigidbody;
};
// update code called every frame
SillyScript.prototype.update = function(dt) {
// Use forces to move the entity based on keyboard input
var force = new pc.Vec3();
if (this.app.keyboard.isPressed(pc.KEY_W)) {
force.y += 1;
}
if (this.app.keyboard.isPressed(pc.KEY_S)) {
force.y -= 1;
}
if (this.app.keyboard.isPressed(pc.KEY_A)) {
force.x -= 1;
}
if (this.app.keyboard.isPressed(pc.KEY_D)) {
force.x += 1;
}
// Normalize the force vector to ensure consistent movement speed
force.normalize().scale(10); // Adjust the scale factor to control movement speed
// Apply the force to the rigid body
this.rigidBody.applyForce(force);
// Set the sprite animation based on the input
if (force.lengthSq() > 1) {
this.entity.sprite.play("sillyMoving");
} else {
this.entity.sprite.play("sillyIdle");
}
};
for movement, it is not the old code and i can not move, please help
https://playcanvas.com/project/1136429/overview/blank-project