Note: The ammo counter displayed over the guns is a simple Text gizmo.
createFloatingText()
method in Floating Text Manager is invoked in the NPCAgent.ts
script when an npcHit is triggered from an axeHit or bulletHit. As a result of a hit, createFloatingText()
generates a piece of floating text bubbling up from the point of impact, displaying the amount of damage done by the hit. This amount of damage is applied to a spawned text gizmo using the setText()
method in FloatingText.ts
. This piece of floating text exists for a predefined period of time, before the Text gizmo is deleted, causing the text to disappear.static propsDefinition = {
floatingTextAsset : {type: PropTypes.Asset, default: undefined},
yPos : {type: PropTypes.Number, default: 2},
floatSpeed : {type: PropTypes.Number, default: 0.5},
rotationSpeed : {type: PropTypes.Number, default: 360},
duration : {type: PropTypes.Number, default: 2.0},
color : {type: PropTypes.Color, default: new Color(1, 1, 1)}
}
Property | Description |
---|---|
floatingTextAsset | Asset in your Asset Library that corresponds to a predefined Text Gizmo asset, in which its properties have been set to create the proper appearance in the world. |
yPos | Y-coordinate offset from the entity from which the new floating text element is spawned. |
floatSpeed | When a floating text element is spawned, it drifts upward. This value defines the speed of the drift in meters per second. |
rotationSpeed | You can define a rotational speed if needed |
duration | Time in seconds that the floating text element should live, before it is destroyed. |
color | Color of the displayed text. |
createFloatingText()
function is invoked from NpcAgent.ts
whenever an axe or bullet strikes an NPC.Behaviour.ts
FloatingText.ts
setText()
specifies the text that appears in the gizmo to which it is attached.update()
is a world event that occurs every frame. This event updates the position and rotation of the floating text based on the specified parameters for it.
Behaviour.ts
FloatingText.ts
script that has been attached to the Text Gizmo.Tip: You can make your own in your own world.
FloatingTextManager.ts
to it.FloatingText.ts
to it.FloatingTextManager.ts
properties, select this asset for the floatingTextAsset property.FloatingTextManager.ts
like the following:FloatingTextManager.instance?.createFloatingText(myString, hitPosition, textColor);
FloatingText.ts
script, rename it, and attach it to a second Text gizmo. You can then change behaviors of individual floating text by modifying parameters in the FloatingText.ts
script.private floatSpeed: number = 1;
private rotateSpeed: number = 360;
private currentTime = 0;
private maxTime: number = 2;
private rotationEuler = new Vec3(0, 0, 0);
private deleted = false;
FloatingTextManager.ts
script.