Forum Discussion
BuenoA
8 months agoPartner
Cant get my script to register hits from a projectile from a projectile launcher.
This is the script for my projectile launcher. (Laser). It works perfectly fine.
import { Entity } from 'horizon/core';
import * as hz from 'horizon/core';
class GrabAndLaunch extends hz.Component<typeof GrabAndLaunch> {
static propsDefinition = {
bullet: { type: hz.PropTypes.Entity },
sound: { type: hz.PropTypes.Entity },
};
start() {
this.connectCodeBlockEvent(this.entity, hz.CodeBlockEvents.OnIndexTriggerDown, this.onTriggerDown.bind(this));
}
onTriggerDown() {
this.props.bullet!.as(hz.ProjectileLauncherGizmo).launchProjectile();
this.props.sound!.as(hz.AudioGizmo).play();
}
}
hz.Component.register(GrabAndLaunch);
This is my script for my "Armor" that will take hits from the projectile. But it will not register any hits.
import { Vec3 } from 'horizon/core';
import { Component, PropTypes, CodeBlockEvents, Entity, Color, Player } from 'horizon/core';
class HitIndicator extends Component<typeof HitIndicator> {
static propsDefinition = {};
start() {
this.connectCodeBlockEvent(this.entity, CodeBlockEvents.OnProjectileHitObject, this.onHit.bind(this));
}
onHit(objectHit: Entity, position: Vec3, normal: Vec3) {
this.entity.color.set(new Color(255, 0, 0)); // set color to red
this.async.setTimeout(() => {
this.entity.color.set(new Color(255, 255, 255)); // reset color to white
}, 500); // reset color after 0.5 seconds
}
}
Component.register(HitIndicator);
Any help would be greatly appreciated. I have all of the properties set correctly in the object to be able to detect collisions from objects, but I can not get the armor to detect any hits.
1 Reply
- MASK.ITMember
hi man, did you manage to get any help with this ?
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 4 months ago
- 9 months ago