Animated NPC (Brief Animation)


#1

https://gyazo.com/a062babfb665fcaeda41c08270c15d32 thanks to @thoys @Konstantin @Judas and @Smokey_Bracken! See George traverse the Music domain.


#2

@KevinMThomas - this is great! Do you have a script you could share? I’d be really interested in extending this - davedub


#3

Hi @davedub I would be glad to! I first want to make special thanks to @thoys and @Konstantin for their hard work putting this together.

jsnpcpatrol.js


#4

Hi @KevinMThomas - Cool, thanks for that. I’m intending to look at applying the walkApi to NPCs as soon as I clear some other projects. I’m currently gathering information atm.

~ I see you’re adjusting the NPC position and rotation via calls to Entities.editEntity. Do you (or @thoys / @Konstantin / @Menithal) know if it’s possible to set rotations on an NPC’s individual joints?

Edit: I just looked through the JS api and found this:

Entities.setAbsoluteJointRotationInObjectFrame

This should give me the control I’m looking for. If anyone has any experience with animating NPCs, I’d really appreciate your input…


#5

The script seems to be gone. Could it be put up again?


#6
//
// JS NPC Patrol
// *************
//
// Created by Kevin M. Thomas, Thoys and Konstantin 04/16/16.
// CC BY
// kevintown.net
//
// JavaScript for the High Fidelity assignment client that initiates an NPC entity and sets it upon a particular velocity as well as runs an external script which adds a talk functionality to the entity upon left clicking it.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
// Audio files has also been included from © Copyright 2008-2016 Amit Sengupta, TrueLogic.org with this license (http://creativecommons.org/licenses/by/3.0).
//
  

// Define time variable in seconds and additional variable declarations.
var goatWalkTime = 300;
var positionOfGeorge = {x: 1, y: .40, z: 3.5};
var positionOfGeorgina = {x: -1, y: .40, z: 3.5};
var goingWestGeorge = true;

// Define NPC properties.
var npcGeorgeTheGoatProperties = {
	type: "Model",
	modelURL: "kgoat10.fbx",
	animationURL: "/kgoat10.fbx",
	script: "jsnpctalk-entity.js",
	lifetime: -1,
	dimensions: {x: 0.56, y: 0.83, z: 0.72},
	position:positionOfGeorge,
	velocity: {x: 0.5, y: 0, z: 0},
	damping: 0,
	angularDamping: 0,
	rotation: Quat.fromPitchYawRollDegrees(0, 90, 0),
	ignoreForCollisions: false,
	shapeType: "box",
	animationSettings: '{"frameIndex": 0, "lastFrame":32, "running": true, "fps": 60, "loop": true}'
};
var npcGeorginaTheGoatProperties = {
	type: "Model",
	modelURL: "kgoat20.fbx",
	animationURL: "kgoat20.fbx",
	lifetime: -1,
	dimensions: {x: 0.56, y: 0.83, z: 0.72},
	position:positionOfGeorgina,
	velocity: {x: -0.5, y: 0, z: 0},
	damping: 0,
	angularDamping: 0,
	rotation: Quat.fromPitchYawRollDegrees(0, -90, 0),
	ignoreForCollisions: false,
	shapeType: "box",
	animationSettings: '{"frameIndex": 0, "lastFrame":32, "running": true, "fps": 60, "loop": true}'
};
 
// Add entities at runtime.
var npcGeorgeTheGoatEntity = Entities.addEntity(npcGeorgeTheGoatProperties);
var npcGeorginaTheGoatEntity = Entities.addEntity(npcGeorginaTheGoatProperties);

// Function that sets an entity or entities into a particular velocity.
var multiple_timer = Script.setInterval(function(){ 
	print("Timer Enabled");
	if(goingWestGeorge) {
		Entities.editEntity(npcGeorgeTheGoatEntity,{
			position: {x: 1+(0.5 * goatWalkTime), y: .40, z: 3.5},
			velocity: {x: -0.5, y: 0, z: 0},
			rotation: Quat.fromPitchYawRollDegrees(0, 270, 0)
		});
		Entities.editEntity(npcGeorginaTheGoatEntity,{
			position: {x: -1 + (-0.5 * goatWalkTime), y: .40, z: 3.5},
			velocity: {x: 0.5, y: 0, z: 0},
			rotation: Quat.fromPitchYawRollDegrees(0, -270, 0)
		});
		goingWestGeorge = false;
	} else {
		Entities.editEntity(npcGeorgeTheGoatEntity,{
			position:positionOfGeorge,
			velocity: {x: 0.5, y: 0, z: 0},
			rotation: Quat.fromPitchYawRollDegrees(0, 90, 0)
		});
		Entities.editEntity(npcGeorginaTheGoatEntity,{
			position:positionOfGeorgina,
			velocity: {x: -0.5, y: 0, z: 0},
			rotation: Quat.fromPitchYawRollDegrees(0, -90, 0)
		});
		goingWestGeorge = true;
	}
}, 1000 * goatWalkTime);

// Delete all cards from world before the game starts each time.
function deleteEntitiesOnExit(){
	Entities.deleteEntity(npcGeorgeTheGoatEntity);
	Entities.deleteEntity(npcGeorginaTheGoatEntity);
}

// Delete entities when exiting script.
Script.scriptEnding.connect(deleteEntitiesOnExit);

#7

Party on man. Party on. :slight_smile:


#8

Thankee most kindly :smiley:


#9

Most welcome!!!


#10

WHOO HOO WHOO WHO WHOO! Oh yea!


#11

What is this script for: script: “jsnpctalk-entity.js”,

and where could I find it, I want to try implementing this. thank you :slight_smile: