Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Limb Resizes When Rotated

Author
Message
kami2awa
3
Years of Service
User Offline
Joined: 18th Mar 2021
Location:
Posted: 18th Mar 2021 10:35 Edited at: 18th Mar 2021 14:59
Hi guys,

I am having a very, very strange issue with DarkBasic.

I'm trying to do something quite ambitious - make an RTS game. Some of my units have turrets which I want to be able to turn to face an enemy. All action takes place on a 2D x-z plane, so all rotation is about the y-axis.

I've written a function to do this, based on the function that makes the units themselves turn (which works fine), using the ROTATE LIMB command in place of ROTATE OBJECT. The model is a .x exported from Blender, with hierarchical limbs (one for each turret).

However, every time the ROTATE LIMB command is called, the following happens:
- The limbs snap position to the centre of the model, instead of where they should be on its wingtips.
- The limbs rotate 90 degrees so that the gun barrel of the turret is pointing straight up.
And most weird of all:
- The turret limbs resize to GIANT size, much bigger than the whole model.

At no point have I resized the limbs in DarkBasic; they are used as-imported from Blender.

Can someone tell me what on Earth is going on here?

Here is the code:


UPDATE: Exactly the same thing happens with SCALE LIMB and OFFSET LIMB. It seems any attempt to move or alter the limbs of the model causes this weird effect. Anyone have any ideas?
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 18th Mar 2021 15:40
Hello,

This brings back memories. I'm not sure where Blender is with hierachical direct X exports. I wrote my own python script for that years ago for DB in blender 2.45 because the included .X export just didn't work right. Anyway, I think someone also wrote their own script that eventually got included in Blender:

https://forum.thegamecreators.com/thread/166987

Anyway, I'd need to see your .x file to see if there is something in the quaternion or the matrix. If there is a scale or rotation in there, that might be affecting your model. I can also understand if you don't want to post that.

The function looks basically correct. You are getting the object angle when it's facing something, resetting it's position, and then rotating the limb at the angle the object was just facing. I think becuase a limb is relative to the objects angle, you are going to need an offset value. For example, if the limb is already at 10 degrees, you can't use the rotate command and set it to 10. It has to be the current limbs rotation + the offset. So if the limb was already at 10 degrees, it's new rotation would be 20.

This would also tie into your limb flipping up to 90 degrees. If the other limb angles are not zero, then you have to again use an offset to the existing angle. Setting a Z or X angle that is currently 90 degrees to zero is going to make it stand up or down on the Y axis

As a test, run through your objects limbs and get their "stationary" angles. Based on what you said they are likely not 0,0,0 .

Also, the limb pivot points may be centered to themselves in you file. For example, If I have a 20 unit long rectangle along the X axis and I want it to rotate around one of it's ends, not it's center, the pivot has to be set to either -10,0,0 or 10,0,0







Enjoy your day.
kami2awa
3
Years of Service
User Offline
Joined: 18th Mar 2021
Location:
Posted: 18th Mar 2021 19:02
OK, after screwing around a ton trying to get Blender to export something sensible, I found a (frankly, pretty ridiculous) workround:

Firstly, I realised I hadn't "applied" all the scaling and so on I'd done to make the model in the first place, so I applied all that in Blender. This would have worked, if the turret and the model have the same rotational axes, which of course they don't. If I set the origin of the turrets in Blender to their centres (rather than the centre of the model), they snap back to the model centre as soon as ROTATE LIMB is used.

Sooo...

For the moveable limbs, I used MAKE OBJECT FROM LIMB to make an independent object, and hid the original limb. You'd think I could then use GLUE OBJECT TO LIMB to lock my new object to the old (now invisible) limb, right?

Nope, that also causes the object to jump to a weird rotation. So, instead, I wrote a routine that locks the turret to the original limb.

Now, I can use my turn_obj function to direct the turret as I would the whole model.

Code:

Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 20th Mar 2021 00:23
Interesting.

I'd really have to dial back the clock but from what I remember, at tleast with my own Blender Script, the Scaling, the Positions, and the Rotations of the limbs when the model is in it resting state all have to be set or committed. I can't right now remember how to do that, but if I have a moment to poke around with an older version of blender, I'll let you know what to do.

For example, if I made a humanoid model and it's resting postion was a T pose, once all the limbs were rotated into that position, that postion has to be committed to 0,0,0. If I had rotated the arm 90 degress on the Z axis so it pointed down the X axis, I have to perform some function in Belnder that now keeps that rotation but resets the angles to 0,0,0. The same with postion, changing the models rotational point, and scaling. You want your model exported with your matrices set to 0,0,0 .

And gluing an object to limb, there's a whole thing about that on these forums including when to use it and when not to use it. Again I vaguely remember positioning an object relative to another object and then offsetting it's position and rotation.
Enjoy your day.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 1st Apr 2021 18:03
I remember one thing now - in Blender, when making your animatable object, click on a limb's intended point of rotation in all three views so you know it's where you want it then from the menu choose Center Cursor. Grab and drag the limbs to where you need them in the object. Rotate them and scale them. Then when you are done with the initial pose, use Ctrl + A to apply the scale and rotation. Press the N key to review the Transform properties. Rotation and scale should be set to zero. Then you can export your model.
Enjoy your day.

Login to post a reply

Server time is: 2024-04-16 11:51:26
Your offset time is: 2024-04-16 11:51:26