Double coding help

I have 2 things I need help with

  1. Turning on and off scripts from a separate script
  2. Freezing an entity in place so you apply tons of force and blast off

if anyone can help with one or both of these I’m all ears
Sincerely William Boersma

Hi William!

First of all, make sure to read the documentation about the pc.Entity: https://developer.playcanvas.com/en/api/pc.Entity.html#script

There you can learn all the properties and methods you can access from any entity in your game.

  1. I can think of two ways of doing so:
otherEntity.script.enabled = false;
//Disable the pc.ScriptComponent of "otherEntity".

 otherEntity.script.scripts[index].enabled = false;
//Disable a specific script
  1. What do you mean exactly with “blast off”? are you trying to collide with that entity?
    if so, you just need to add Rigidbody and Collision component to that entity. Make sure to set the Rigidbody type to “static”.
1 Like

I think you also need to define an object where the script is attached on in initialize.

ex.:

this.ObjectWithScript = this.app.root.findByName('ObjectWithScriptAttached');

and use this.ObjectWithScript.script.enabled = false; in specific part of code you want

I used finding by name, but you can also find object by tag or with other methods you can see in documentation.

The way of freezing entities is to set this.app.timeScale = 0;

but to freeze one entity it depends whether you using physics or just translate method.

https://developer.playcanvas.com/en/api/pc.Application.html#timeScale

Hi @Francisco_Bozzo I got the freezing but the turning on and off scripts still doesn’t work.

never Mind I got it

1 Like