[SOLVED] Detect when you are hovering an entity with the mouse

I need change the color of an entity when the cursor hover it.

Here is a helpful tutorial on entity picking: https://developer.playcanvas.com/en/tutorials/entity-picking/ . You can change this to always pick an entity on every frame and when an entity is picked change its color.

To change the color you could do something like

var color = new pc.Color(1, 0, 0);
var meshInstances = this.entity.model.meshInstances;
for (var i = 0; i < meshInstances.length; i++) {
  meshInstances[i].material.diffuse = color;
  meshInstances[i].material.update();
}

Note that if the material on each mesh instance is shared by other models then they will all change color. In that case you should assign a cloned copy of a material to each mesh instance so that you don’t affect other models.

1 Like

Thanks, but I know how to do it picking, but i want that it changes when you hover it, not picking.

Then use mouse move event inside of mouse click.

What’s difference between picking and hover?

Pick when you do click and hover when you just pass?

When we say entity picking we do not refer to ‘clicking’ or ‘hovering’ we only refer to finding out which entity is under the cursor. When you do the entity picking is up to you, you can do it after a click, you can do it when the mouse moves etc.

2 Likes

Oh, thanks for that information!