Need help with onclick model creation script



I was wondering if there is an easy way to combine the createCow tutorial script with some kind of onClick event or even some kind of “entering a zone” event.

I am wanting it where a model will spawn when a user clicks onto another model (let’s say a cube). Can I get some assistance with this?



Theres a couple of issues stopping a simple answer to your request but I will do my best.

The createCow script is a client script but a click entity is an entity script so there needs to be some extra code changes to make the 2 work together, heres a simple click entity script to change colors.

var clicked = false;
this.mousePressOnEntity = function(entityID, mouseEvent) {
if (clicked){
Entities.editEntity(entityID, { color: { red: 0, green: 255, blue: 255} });
clicked = false;
Entities.editEntity(entityID, { color: { red: 255, green: 255, blue: 0} });
clicked = true;

put that in a cube and click it, now play with the params and get to know it.
here is its bare bones, look at the log for the “Clicked” output to know its working.

this.mousePressOnEntity = function(entityID, mouseEvent) {

(edited to remove some incorrect info)
So start with a simple Entities.addEntity before you try to create that cow with its scripts and animations.


If you prefer the enter instead of click then just replace

this.mousePressOnEntity = function(entityID, mouseEvent)


this.enterEntity = function(entityID)

and make it big enough and remove any collisions so you can actually enter it, and make it invisible for obvious reasons, but in my experience the enter entity tends to trigger more than once and this can cause issues.