MCPcopy Create free account
hub / github.com/defold/defold / Script_SetScale

Function Script_SetScale

engine/gameobject/src/gameobject/gameobject_script.cpp:1055–1079  ·  view source on GitHub ↗

sets the scale factor of the game object instance * The scale factor is relative to the parent (if any). The global world scale factor cannot be manually set. * * [icon:attention] See manual to know how physics affected when setting scale from this function. * * @name go.set_scale * @param scale [type:n

Source from the content-addressed store, hash-verified

1053 * ```
1054 */
1055 static int Script_SetScale(lua_State* L)
1056 {
1057 Instance* instance = ResolveInstance(L, 2);
1058
1059 // Supports both vector and number
1060 Vector3* v = dmScript::ToVector3(L, 1);
1061 if (v != 0)
1062 {
1063 Vector3 scale = *v;
1064 if (scale.getX() <= 0.0f || scale.getY() <= 0.0f || scale.getZ() <= 0.0f)
1065 {
1066 return luaL_error(L, "Vector passed to go.set_scale contains components that are below or equal to zero");
1067 }
1068 dmGameObject::SetScale(instance, scale);
1069 return 0;
1070 }
1071
1072 lua_Number n = luaL_checknumber(L, 1);
1073 if (n <= 0.0)
1074 {
1075 return luaL_error(L, "The scale supplied to go.set_scale must be greater than 0.");
1076 }
1077 dmGameObject::SetScale(instance, (float)n);
1078 return 0;
1079 }
1080
1081 /*# sets the scale factor only for width and height (x and y) of the game object instance
1082 * The scale factor is relative to the parent (if any). The global world scale factor cannot be manually set.

Callers

nothing calls this directly

Calls 8

ResolveInstanceFunction · 0.85
ToVector3Function · 0.85
luaL_errorFunction · 0.85
luaL_checknumberFunction · 0.85
SetScaleFunction · 0.70
getXMethod · 0.45
getYMethod · 0.45
getZMethod · 0.45

Tested by

no test coverage detected