Shortbow Tutorial Help


#1

I’m a non-HMD user attempting to to setup this shortbow tutorial that’s on the HF blog. The issue I’m having is trying to figure out how to equip the shortbow. I click on it and it does nothing. I can click+drag it around, but that’s about it. Is this tutorial only HMD-friendly? In the File -> Help information, I don’t see any shortcuts mentioned for equipping items for non-HMD keyboard users.


#2

You try to use the shortbow with a mouse ?
As far i know that’s not working. it’s made for the HMD and handcontrollers.


#3

Ok. Was figuring so. I tried some weapons on the marketplace and I had the same issue.

So, the question is… is it possible to make mouse-friendly equippable items in HF at all, or will the developers have to code in the support?

Just seems like favoritism to HMD to support this type of stuff on HMD’s only. In a world of Responsive Web Design and cross-device integration, that mouse and HMD would be a seamless experience.


#4

I was playing with this (that is mouse clicking to equip to avatar) the other night and noticed that you can attach items to your avatar. Will see where this goes. Although, I was having a heck of a time trying to get things to work like I would expect them to and consistently. I’ll post this in another post.


#5

I’ve made some progress with mouse/keyboard-based script.

So far, it can…

  • Equip on click
  • Unequip on key press
  • Fire on key press

It’s only coded to work with my particular setup so far. Here are the scripts…

itemSpawner.js

var id = Entities.addEntity({
	"position": MyAvatar.position,
	"collisionsWillMove": 1,
	"compoundShapeURL": Script.resolvePath("bow_collision_hull.obj"),
	"dynamic": 1,
	"gravity": {"x": 0, "y": -9.8, "z": 0},
	"modelURL": Script.resolvePath("bow-deadly.fbx"),
	"name": "Hifi-Bow",
	"script": Script.resolvePath("itemController.js"),
	"shapeType": "compound",
	"type": "Model",
	"lifetime": 600
});

print ("itemSpawner.js v1.0 loaded");

itemController.js

(function() {
	var _this;
	var _modelURL;
	
	var extKeyPressEvent = function(event) {
		switch (event.text) {
			case "SPACE":
				print("FIRE!");
				break;
			case "q":
			case "Q":
				MyAvatar.detachOne(_modelURL);
				Controller.keyPressEvent.disconnect(extKeyPressEvent);
				Entities.addEntity({
					"position": MyAvatar.position,
					"collisionsWillMove": 1,
					"compoundShapeURL": Script.resolvePath("bow_collision_hull.obj"),
					"dynamic": 1,
					"gravity": {"x": 0, "y": -9.8, "z": 0},
					"modelURL": Script.resolvePath("bow-deadly.fbx"),
					"name": "Hifi-Bow",
					"script": Script.resolvePath("itemController.js"),
					"shapeType": "compound",
					"type": "Model",
					"lifetime": 600
				});
				print("Attachment removed and respawned");
				break;
			default: break;
		}
	};
	
	EquipItem = function() {
		_this = this;
		_modelURL = this.attachment.modelURL;
	};
	
	EquipItem.prototype = {
		attachment: {
			modelURL: Script.resolvePath("bow-deadly.fbx"),
			jointName: "LeftHand",
			translation: {"x": 0, "y": 0.020, "z": 0.030},
			rotation: Quat.fromVec3Degrees({"x": 0, "y": 90, "z": -90}),
			scale: 1,
			isSoft: false
		},
		
		// Overrides
		
		mousePressOnEntity: function(entityID, mouseEvent) {
			MyAvatar.attach(
				this.attachment.modelURL,
				this.attachment.jointName,
				this.attachment.translation,
				this.attachment.rotation,
				this.attachment.scale,
				this.attachment.isSoft
			);
			Entities.deleteEntity(entityID);
			Controller.keyPressEvent.connect(extKeyPressEvent);
		}
	}
	
	print("itemController.js v1.0 loaded");
	
	return new EquipItem();
})