Canardia Posted November 30, 2009 Share Posted November 30, 2009 I tried to add a propeller to the rear of the airplane, but no matter how I joint it, it always rotates the airplane too, when I turn the propeller (model is the airplane, target is the propeller), and I try to turn the target around its Z axis: CreateJointHinge(model,target,Vec3(-1,0,-1.67),Vec3(0,0,-1.67)) A similar code works fine in C++, and I can turn the target around its Y axis: CreateJointHinge(model,target,Vec3(-1,3,0),Vec3(0,3,0)) Btw, a documentation how joints should be used would be also nice, so far I've been only guessing Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Rick Posted November 30, 2009 Share Posted November 30, 2009 I tried to add a propeller to the rear of the airplane, but no matter how I joint it, it always rotates the airplane too, when I turn the propeller (model is the airplane, target is the propeller), and I try to turn the target around its Z axis: CreateJointHinge(model,target,Vec3(-1,0,-1.67),Vec3(0,0,-1.67)) A similar code works fine in C++, and I can turn the target around its Y axis: CreateJointHinge(model,target,Vec3(-1,3,0),Vec3(0,3,0)) Btw, a documentation how joints should be used would be also nice, so far I've been only guessing Can you show the complete lua code. Quote Link to comment Share on other sites More sharing options...
Canardia Posted November 30, 2009 Author Share Posted November 30, 2009 For the airplane: function Initialize() for model,entity in pairs(entitytable) do local target = model:GetTarget(0) if target~=nil then AppLog("TARGET 0 FOUND") pos = model:GetPosition() pos.y = pos.y + 0.02 pos.z = pos.z - 1.67 target:SetPosition(pos) rot = EntityRotation(model) target:SetRotation(rot) CreateJointHinge(model,target,Vec3(-1,0,-1.67),Vec3(0,0,-1.67)) end end end For the propeller: function UpdatePhysics(model) local entity,model for model,entity in pairs(entitytable) do if entity.active~=0 then model:AddTorque( Vec3( 0, 0, 100 ) ) end end end Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Rick Posted November 30, 2009 Share Posted November 30, 2009 My guess would be that the propeller code is adding torque to the plane as well. This is my confusion around what is stored in entitytable and how to find the entity you want when looping over it. From my understanding entitytable holds all entities loaded. So this would mean your plane and propellers are in this table. If that's the case it would be adding torque to both, which is what you are seeing. Other possible things: You have 2 model variables. The param coming in is named model also, so there might be confusion there. Is the parameter to UpdatePhysics() the model or the world? I know Update() passes in the world but one of the scripts I saw named it model, which Josh said was a bad variable name because it should have been world. Quote Link to comment Share on other sites More sharing options...
Josh Posted November 30, 2009 Share Posted November 30, 2009 Why are you using a non-normalized vector for the pin? Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Canardia Posted November 30, 2009 Author Share Posted November 30, 2009 I don't know if the Pin is relative or absolute to the Position vector. Like I said, I'm just trying and guessing, since there is no documentation how joints should be used (not even on the Newton forum, and they don't have a wiki of the commands either). Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Josh Posted November 30, 2009 Share Posted November 30, 2009 The pin is the vector around which the joint rotates. Do not confuse this directional vector with a position. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Canardia Posted November 30, 2009 Author Share Posted November 30, 2009 I tried all combinations, but it still rotates model, when I rotate target around its Z axis: CreateJointHinge(model,target,Vec3(0,0,-1.67),Vec3(0,0,1)) CreateJointHinge(model,target,Vec3(0,0,-1.67),Vec3(0,0,-1)) -- maybe pin needs be outside of both bodies? CreateJointHinge(target,model,Vec3(0,0,-1.67),Vec3(0,0,1)) -- maybe target should be jointed to the model, and not vice versa? CreateJointHinge(target,model,Vec3(0,0,-1.67),Vec3(0,0,-1)) CreateJointHinge(model,target,Vec3(0,0,-30),Vec3(0,0,1)) -- maybe both position and pin needs to be outside both bodies? Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Josh Posted November 30, 2009 Share Posted November 30, 2009 Example? Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Canardia Posted November 30, 2009 Author Share Posted November 30, 2009 I tried to make a standalone LUA demo, and it works fine there, when I used Vec3(0,0,0) as position and Vec3(0,0,1) as pin. I can't figure out what's different in Editor. dofile("scripts/base.lua") RegisterAbstractPath("") Graphics(800,600) fw=CreateFramewerk() DebugPhysics(1) model=CreateBodyBox(1,1,4) pos=model:GetPosition() target=CreateBodyCone(1,1) target:Move(Vec3(0,0,-2.7)) target:Turn(Vec3(90,180,0)) fw.main.camera:SetPosition(pos) fw.main.camera:Turn(Vec3(0,-90,0)) fw.main.camera:Move(Vec3(0,0,-10)) model:SetMass(1) target:SetMass(1) SetBodyGravityMode(model,0) SetBodyGravityMode(target,0) CreateJointHinge(model,target,Vec3(0,0,0),Vec3(0,0,1)) while(KeyHit(KEY_ESCAPE)==0) do target:AddTorque(Vec3(0,1,0)) model:AddTorque(Vec3(0,2,0)) fw:Update() fw:Render() Flip(0) end Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Josh Posted November 30, 2009 Share Posted November 30, 2009 The way you are looping through all the entities to find the target is kind of backwards. You know you want your plane to have a propeller. You don't need to place it in the editor every time you want a plane. It's far easier just to do this in the spawn function: Function Spawn(model) entity=base_Spawn(model) entity.propeller = LoadModel( "abstract::propeller.gmf" ) If entity.propeller~=nil then attachmentposition=TFormPoint(Vec3(1,0,1),model,nil) entity.propeller:SetPosition( attachmentposition ) CreateJointHinge( model, entity.propeller, attachmentposition, Vec3(0,0,1) ) End End Make sure you get rid of the propeller in the Kill function: Function Kill( model ) entity=entitytable[ model ] If entity~=nil then If entity.propeller~=nil then entity.propeller:Free() entity.propeller=nil End End base_Kill(model) End I used this kind of automatic subobjects in the train cars to attach wheels to the car. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Canardia Posted November 30, 2009 Author Share Posted November 30, 2009 Thanks, that works much better, but if I do all attachments to the airplane this way, I lose all property dialogs in Editor. For example the smoke emitter is really nice to have in Editor, and not in code. I think I will just use TurnEntity() on the propeller, since Newton has a problem with high speed rotations also. The wheels can be done by code, as they don't need any adjustments in Editor. The engine exhaust smoke should be done in Editor, as it's too much coding to make particles by code. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Josh Posted December 1, 2009 Share Posted December 1, 2009 If the propeller isn't going to be interacting with any physical objects, there's no need to bother using a joint. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Canardia Posted December 1, 2009 Author Share Posted December 1, 2009 It should still have its convex collision hull, but that works also when rotating it with TurnEntity(), it just won't get affected by other physics bodies, but the other physics bodies will. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.