Stop after pop up alert

Please help me, I want to make the character stop moving after the pop up appears. sorry because I’m a beginner.
this is my project

Hi @Unavailable and welcome,

Check the following UI example on adding UI buttons/popups and how to execute code as a response to a button click:

When the buttons is clicked one way to stop your player from moving, is to disable the playerMovement script:'Player').script.playerMovement.enabled = false;
1 Like

I still don’t understand. it was created in CollisionAlert.js right?

Hi @Unavailable!

You put it into the “onPress” function which only triggers when you press pc.KEY_SPACE.

CollisionAlert.prototype.onPress = function (event) {'Player').script.playerMovement.enabled = false; };

Try putting the line into the onCollisionStart function :slight_smile:

1 Like

Yeah, this exactly, and most likely you also want
“‘Player’).script.playerMovement.enabled = true;” where you currently have it in the Space key trigger function so that they can continue walking after they make the popup go away.

1 Like

I tried it but after I pressed the space bar the character still moves, is there something wrong?

CollisionAlert.prototype.onPress = function (event) { 
    if({'Player').script.playerMovement.enabled = true;

This part => enabled = true; means movement is enabled. If you wish to disable it try enabled = false;

The thought was: you might want to “release” the player with SPACE if he get’s stopped by the collisionbox.

1 Like

yes I want to make after pressing the space after the pop up character can move again. but after pressing the space character moves in place. and after pressing SPACEBAR again the character continues to move forward.

i think it doesn’t work

You have to bind the pc.EVENT_KEYDOWN event and not a specific key.

var CollisionAlert = pc.createScript('collisionAlert');
CollisionAlert.attributes.add('targetEntity', {type: 'entity'});
CollisionAlert.attributes.add('Player', {type: 'entity'});

// CollisionAlert.attributes.add('Player1', {type : 'entity'});

// // initialize code called once per entity
CollisionAlert.prototype.initialize = function() {
    this.entity.collision.on('collisionstart', this.onCollisionStart, this);, this.onPress, this);

CollisionAlert.prototype.onCollisionStart = function(entity) {    
    var player =;
    var target =;
    var playerCollision = this.entity.findByName('Player');
    if (entity.other.rigidbody) {'Player').script.playerMovement.enabled = false;
        setTimeout(function() { alert("this " + player + " hit the " + target + " ,press space to close"); }, 200);

CollisionAlert.prototype.onPress = function (event) {
    if(event.key === pc.KEY_SPACE) {
        console.log("SpacePress");'Player').script.playerMovement.enabled = true;

But this creates a new problem: You won’t get the SpaceKey event from the alert. So you have to press Space 2 times.

I would suggest instead of using alerts you could set up a simple 2D Screen to show your Text.

Can I disable other scripts like Player Movement? i tried to disable movementSound and playerAnimation with the same text it doesn’t work.

Sure you can. But you can’t access them with “script”:'Player').script.playerMovement.enabled = false;

Try sound or animation instead. But first read up on how to use them right: