Models and Primitives Behave Differently?


#1

I set up some objects as primitives (Spheres) and they behave as I expect them too; they have a velocity and gravity that cause them to pop up and fall. If I set the type to “Mesh” and specify a .fbx via a modelURL they don’t do what I expect, which would be to look different but act exactly the same. Instead, they float up a bit and drift to a stop instead.

I have no idea what’s causing this. Any insight would be appreciated.


#2

Its really not possible to change the type from primitive to mesh, I’m not sure what you are doing there.
When you first select “Create” you get the option of importing a mesh “Model” or
generating a system primitive “CUBE or SPHERE”, or any of the other entity types.

If you want to import a mesh model select “Model” and then put in the URL to the fbx. Then if you want velocity you must set the Collisions to be anything but “Exact”.
Once it is imported you can then set the velocity etc.


#3

This might better explain. I’m not trying to change the type on the fly. I change the type used in my Entities.addEntity() and re-run the script. Both versions of the entities are created with the same code minus the type and modelURL:

// This
var id = Entities.addEntity({
type: “Sphere”,
// Everything else is the same
});

// Versus

    var id = Entities.addEntity({
        type: "Model",
        modelURL: modelURL,
       // Everything else is the same
    });

The “same” entity isn’t acting in the same manner in this case. My entities are set to collisionless: true


#4

I’ve spent a fair amount of time (too much time?) trying to figure this out and one thing I’ve found is what appears to be discrepancies or inaccuracies in the API documentation for entity properties. For instance, the description of the gravity property states that it will only take effect if the dynamic property is set to true. This does not appear to be the case. In fact, the description for the dynamic property makes it seem it has a very different effect. This has led to a lot of trial and error on my part to see the effect of these properties in game as I try to find out what is wrong. Any additional help to limit this trial an error approach would be appreciated :slight_smile:


#5

Could you post the entire script (the create params at least)
is it a client script? Models do behave quite differently to primitives in some cases especially in assignment scripts.
Yes the API doc may not be accurate.
True that dynamic does not seem to need to be checked for velocity.
Looking at your script may help me understand whats happening.


#6

I can most certainly share the script. I’ll try to keep it to the relevant bits rather than the whole thing.

It is a client script.

The current state of what I hope is relevant is :

– Object Creation –

   var id = Entities.addEntity({
        position: position,
        rotation: rotation,
        "script": Script.resolvePath("entity.js"),
        type: entityType, // Passed "Sphere" or "Model" - all are of the same type when the project runs.
        modelURL: models[randomIndex], // twin arrays for models and dimensions, below, are used for randomness on creation
        color: pickRandomColor(),
        dimensions: dimensions[randomIndex],
        dynamic: false,
        collisionless: true,
        lifetime: 300
    });

– And what I do with it when I see the different behaviors –

_this.drop = function(entityID){
    var newProperties = {
        gravity: {x: 0, y: -2.4, z: 0},
        velocity: {x: Math.random() - Math.random(), y: Math.random() * -1, z: Math.random() - Math.random()}
    };
    isAlive = true; // This is for my own use in other scripts    
    Entities.editEntity(entityID, newProperties);
    print("drop balloon");
    this.startKill(this.entityID);  // This starts a Timeout to tell it what to do after the entity has been dropped.
};

#7

Welcome to Hifi.
Docs are out of date, Behaviour is not consistant nor predictable. Be prepared to pull your hair out, it just the way things are around here. They seem to not need Dynamic out of the box but for continued reliable results keep the Dynamic checked or it will suddenly stop working for no reason.
Setting things with a script dont always result in the same settings as by checking the edit window, discrepencies do occur.
I just tested the gravity and it doesnt even do the same thing twice, it is very unpredictable.
Entering a value into gravity will adjust the Linear velocity for that axis, if you then set linear velocity it will interfeer with the gravity settings. I suggest either set gravity or set linear velocity and set damping to zero, but not both.
Collisions need to be set so the object will bounce off a collidable floor or each other. But use simple colliders.
Models do behave differently to primitives so test for exactly what you want and dont expect the results to be transferrable. I hope this helps reduce your trials and errors.


#8

I’m a little confused by the comment on linear velocity conflicting with gravity. This seems to be at odds with the documentation and my experience. The documentation states “Due to the way the physics system currently works, an entity must be assigned a small velocity (~0.01m/s) in conjunction with gravity in order for gravity to be effective.” This appears to be true via testing. Am I misunderstanding something?


#9

And I’ve found the problem. The meshes did not like the default “shapeType: none” Changing this to another type (sphere in this case) caused the mesh object to behave as expected.