tomotani
6 months agoMHCP Member
Desktop Editor raycast issues?
Hi everyone,
I’m running into an issue that I thought would be fairly straightforward.
I’m trying to use a laser-pointer–style object to grab and interact with objects for a simple puzzle game. The problem is that my raycast isn’t logging any hits on the tagged objects.
To troubleshoot, I set up a minimal test:
- Created a cube as my grabble object
- Attached a raycast to it
- When grabbed, the raycast should change the color of a simple sphere
But I’m still not seeing any hits registered.
Here’s the simplified script I’m testing with:
import { Raycast, Entity, Color, Component } from 'horizon';
export class LaserColorChanger extends Component<typeof LaserColorChanger> {
static override typeName = "LaserColorChanger";
private raycast: Raycast | null = null;
start() {
this.raycast = this.entity.getComponent(Raycast);
}
update() {
if (!this.raycast) return;
const hit = this.raycast.getHit();
if (hit && hit.entity && hit.entity.name === "TargetSphere") {
hit.entity.getComponent("MeshRenderer").setColor(Color.red());
console.log("Hit TargetSphere!");
}
}
}Has anyone else run into this or see what I might be missing?
Thanks in advance!