Having issues with a server script that edits entity velocity


I’m having an issue with a server script I modified from one found in the documentation:

This works, but then I made a modification so that it modifies an Entity velocity when it reaches a particular position here is the script:

print(“Server Mayor script 3”);

(function() {
//this script changes the velocity of entity to zero when it reaches position -161…but its not working…
var self = this;

this.preload = function(entityID) {

    self.intervalID = Script.setInterval(function() {

	var entityPosition = Entities.getEntityProperties(entityID, 'position' ).position;
	print("entity position z" + entityPosition.z );

		if( parseFloat(entityPosition.z) > -161 ) {
			print("hit -161" + entityPosition.z );
			print("entity ID" + entityID );
				var results = Entities.editEntity(entityID, { 
				velocity: {x: 0, y: 0, z: 0}, 
				animationURL: "http://www.flyshopmiami.com/highfidelity/models/BARBIE-Talking-113F.fbx", 
				position:  { x: 86, y: 2.84, z: -161 }, 
				rotation: Quat.fromPitchYawRollDegrees(0, -90, 0) 
			print("entity results" + results );		

    }, 10);

this.unload = function() {


-When the entity reaches the position, it executes the if statement. The print statement says that its new postion is -161 but the entity in world continues moving… it doesn’t stop, even though the print statement keeps printing -161 as if it was not moving, while the entity itself keeps moving.

in summary: The edit entity command doesn’t work when it runs on the server, it says that it stopped moving since it prints a steady position, but the entity keeps moving, un affected by the the velocity of zero.


There is a few things to take note that probably are not mentioned in the documentation, but mentioned in my lil post:

Velocity, and other physical attributes are currently never simulated by the server.

Instead this simulation is accomplished by any client that is nearby and connected, as physics in high fidelity work by distributed physics simulation, where every client in a scene simulates the entities they are closest to or are interacting with.

You can basically set the velocity, but it will never update nor never more, unless there is an agent present in the scene.

So in this case, the velocity will stay the same, and so will the position. The velocity also is not affected by friction, because it is currently “not active” as there is no one owning the simulation.

This is also why you cannot have a physical object that is locked, as the client cant move the entity around according to its calculations.

That being said, since you are talking about entity server scripts, make sure your entity not locked, it should still work, as long as someone is around to simulate the physics, just note that it will stay at last position until another takes over.

Just note that any hick up in server fps, may cause latency in it changing its physics properties, so take that to account.

Better way would be to use Physics Actions however, but that is not very well documented at all, and possibly, only accessable by client script (I have not tested it with entity server scripts)


If you need something following a waypoint, then having the entity server script call up anAssignment client to behave as an avatar would work better.