SpawnModel

If there is something important you think is missing in the current version of ZGameEditor then you can post a feature request here!

Moderator: Moderators

User avatar
y offs et
Posts: 418
Joined: Wed Apr 22, 2009 4:26 pm
Location: BC, Canada

SpawnModel

Post by y offs et »

Currently, we can use Repeat/SpawnModel and using a model identity, place multiple instances differentiated by position alone - not rotation or scale.

As SpawnModel is the final set for position, rotation, scale, in that it's settings tend to overrule Model sets, it would be desirable that rotation and scale of SpawnModel could also be affected by scripting.

Yes, Kjell, I hope you can prove me wrong. :D
"great expectations"
User avatar
Kjell
Posts: 1915
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

:?

See attached .. but perhaps I'm missing something. What are you trying to do exactly?

K
Attachments
Spawn.zgeproj
(886 Bytes) Downloaded 616 times
User avatar
y offs et
Posts: 418
Joined: Wed Apr 22, 2009 4:26 pm
Location: BC, Canada

Post by y offs et »

OK, I give up trying to explain. On this, I've made individual models of the pieces because that way I get the collision working right. So I can double my instances via position, but I can't figure how to rotate an instance.
Attachments
animSprite_7.zip
(31.9 KiB) Downloaded 545 times
"great expectations"
User avatar
Kjell
Posts: 1915
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

:?

Going out on a limb here .. but I'm guessing that the collision doesn't work the way you want it anymore when you spawn a rotated model? If so, this is because Box3D != Box3D_OBB .. you'll need to update the Bound properties to match the instance.

K
User avatar
y offs et
Posts: 418
Joined: Wed Apr 22, 2009 4:26 pm
Location: BC, Canada

Post by y offs et »

OK - I learned something here so I won't say sorry.

In the previous - base:model / OnSpawn / make_cell:repeat - there are two script lines besides the default //this.iteration ...
Even though they are commented out, they prevent the iterations! By removing them, the models are spawned. I consider this a bug.

@VilleK - your call - I can make note of this in the Docs, or you can fix it.

Now, in Group cell / Cell:Model / OnSpawn / ZExpression - I create the second instance by moving the position, however I cannot affect the rotation or scale. Why not?
Attachments
animSprite_7.zip
(31.81 KiB) Downloaded 526 times
"great expectations"
User avatar
Kjell
Posts: 1915
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

:)

Ah, now I get it. The UseSpawnerPosition checkbox only assigns the CurrentModel's Position to the Spawned model, not the Rotation or Scale ( otherwise it would be called UseSpawnerTransformation ). Check my example for the two methods you can use to do just that.

K
User avatar
y offs et
Posts: 418
Joined: Wed Apr 22, 2009 4:26 pm
Location: BC, Canada

Post by y offs et »

@Villek - About the WhileExp in the Repeat Component - It seems any kind of entry other than the default line activates it and nullifies the Count. This can't be right. It's a noob tripper ( it tripped me :) )

@Kjell -
( otherwise it would be called UseSpawnerTransformation )
You're right - literal translation. If it did everything it could be called UseSpawnerAttributes. Thanks for those methods. I'll see what I can come up either with a ZExpression or using the hyper sensitive WhileExp box.
"great expectations"
User avatar
y offs et
Posts: 418
Joined: Wed Apr 22, 2009 4:26 pm
Location: BC, Canada

Post by y offs et »

As SpawnModel is the final set for position, rotation, scale, in that it's settings tend to overrule Model sets, it would be desirable that rotation and scale of SpawnModel could also be affected by scripting.
Just a follow up - it appears that by having the individual parts being SpawnModel (ed) in the OnSpawn list of Cell, they overrule any method of rotating the model via Cell.rotation, so I'll have to find another way.

Just another example that SpawnModel is the final, overruling set on anything.
"great expectations"
User avatar
Kjell
Posts: 1915
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

:?

Strange .. both methods work just fine from me ( regardless of context ).

K
Attachments
Spawn.zgeproj
(1.53 KiB) Downloaded 607 times
User avatar
y offs et
Posts: 418
Joined: Wed Apr 22, 2009 4:26 pm
Location: BC, Canada

Post by y offs et »

I'll rebuild my project and get back to you. :?

As an aside, I noticed in your last spawn example you declared variable Count in Content and then called it immediately in OnLoaded. That says to me that Content must be loaded before OnLoaded and calls into question the accuracy of
OnLoaded
This list is executed once at program start. Put your application initialization components here.
Any comment on this?
"great expectations"
User avatar
Kjell
Posts: 1915
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

:)

Both the OnLoaded description and your assessment are correct.

Technically it doesn't matter where you put your DefineVariable Components .. you can even put them all in a OnCollision event of a ModelState :P

K
User avatar
y offs et
Posts: 418
Joined: Wed Apr 22, 2009 4:26 pm
Location: BC, Canada

Post by y offs et »

OK, here's another problem.
The black is the parent model and blues are child models.
As I change parent position the children follow, we can do that.
As I rotate parent, the children rotate also, You showed a way to do that.
But their position relative to the internal layout does not transform.

I haven't been able to dream up a simple way to do this, other than a one piece .3ds model. Pascal, being OOP, I thought could have a solution.

Why do I torture myself this way? :cry:

EDIT - I'm thinking the only way is having 4, or whatever, complete parents with the internals oriented as desired, and transform them where desired. I'm also starting to mumble while thumbing my lips and rolling my eyes, and am thinking about pointy hats. We don't seem to have an Emoticon to portray that.
Attachments
no_transform.gif
no_transform.gif (1.33 KiB) Viewed 13263 times
"great expectations"
User avatar
Kjell
Posts: 1915
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

:?

Yea .. those kinds of things would be allot easier if ZGE supported hierarchies.

Anyway, you need to rotate around the center / pivot of the parent ( which influences the position ), instead of just rotating the individual children themselves. So, calculate the distance of the child position to the parent, and multiply those coordinates with the following formula ( when rotating over the y axis ).

Code: Select all

X = DistanceX*cos(Angle)-DistanceZ*sin(Angle);
Z = DistanceX*sin(Angle)+DistanceZ*cos(Angle);
In case you need to rotate over more then 1 axis, use the matrix library.

K
User avatar
y offs et
Posts: 418
Joined: Wed Apr 22, 2009 4:26 pm
Location: BC, Canada

Post by y offs et »

I knew you'd come up with something.
I've got real life interfering with hobby right now, but I'll put this all together somehow in the future.
"great expectations"
User avatar
VilleK
Site Admin
Posts: 2355
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

y offs et wrote:In the previous - base:model / OnSpawn / make_cell:repeat - there are two script lines besides the default //this.iteration ...
Even though they are commented out, they prevent the iterations! By removing them, the models are spawned. I consider this a bug.
You are right, that was a bug but it will be fixed in the next beta update :)
Post Reply