cassius Posted November 15, 2011 Share Posted November 15, 2011 I have coded my enemy character to follow my main character wherever it goes. If I set the mass of the enemy character to anything oyher than 0.0 it will not follow my main character up stairs. On the other hand if I set the enemy character mass to 0.0 it WILL follow her up stairs but there is a snag. With the enemy nass set to 0.0 it floats slightly above ground level. So neither methods are entirely satisfactory. So whats the common practise for combining physics with animation? Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
Pixel Perfect Posted November 16, 2011 Share Posted November 16, 2011 I'm not entirely sure why, with a mass set, your NPC is not climbing the stairs. How are you moving your NPC? Is it using a character controller? Are you simply applying insufficient force to move your character? I take it if you are using a character controller that it has a suitable step height and slope angle set otherwise it wouldn't climb the stairs with the mass set to zero either! Quote Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++ Link to comment Share on other sites More sharing options...
cassius Posted November 16, 2011 Author Share Posted November 16, 2011 I only use a controller for the main character which is third person style and moves in front of the camera. Its the enemy characters I have problem with. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
Wchris Posted November 16, 2011 Share Posted November 16, 2011 So whats the common practise for combining physics with animation? As Pixel suggested, the common practice is to use controllers for both players and non players characters. Quote Windows 7 home - 32 bits Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM Link to comment Share on other sites More sharing options...
cassius Posted November 16, 2011 Author Share Posted November 16, 2011 thanks. Are there any examples of non player character controllers around? Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
cassius Posted November 16, 2011 Author Share Posted November 16, 2011 Just to clarify things here is what I do with characters after conversion to gmf. Place character in editor use phygen to give it a cube shaped physics body set mass and other properties. Does anyone do different to this??? such as doing the whole thing in code. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
Rick Posted November 16, 2011 Share Posted November 16, 2011 Yeah, I would create a character controller for the characters and update it in their model scripts update method. I would make a global function called GiveGlobalCharacterAttributes(obj) and call that at the start of the class script for each character passing that script object itself. Inside this function is where you could give all the attributes. obj.controller = CreateController(...) obj.health = 100 obj.etc That way if you want to add a global attribute to all these separate character models you have 1 central place to do it. There are other ways to do this also but this is generally the "easiest" Quote Link to comment Share on other sites More sharing options...
Wchris Posted November 17, 2011 Share Posted November 17, 2011 use phygen to give it a cube shaped physics body set mass and other properties. I never use phygen for characters. The controller allready has a cylinder shaped physics body. All you have to do is to adjust it's size to your character size and then position the character mesh inside the controller cylinder. use debugphysics to view the cylinder. Quote Windows 7 home - 32 bits Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM Link to comment Share on other sites More sharing options...
cassius Posted November 17, 2011 Author Share Posted November 17, 2011 yeah. This issue is something I missed despite a clear explanation on the wiki. So I will have to use controllers starting now. Thanks for advice. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
cassius Posted November 18, 2011 Author Share Posted November 18, 2011 Ok I have set up a controller for my enemy character and it works ok exept it will not move toward my main character as it did nefore using moveentity' I also don't know what values to put in updatecontroller Heres the code Global barbarian_1:TModel = LoadModel("abstract::barbarian_barbarian.gmf") Global barb_control:TController = CreateController() PositionEntity(barb_control,EntityPosition(pos)) EntityType(barb_control, 3) SetBodyMass(barb_control, 10.0) SetBodyBuoyancyMode(barb_control,0) Global barb_body:TBody = Createbodybox(0.6,1.9,0.6) ScaleEntity(barb_body,Vec3(0.8,3.0,0.6)) EntityParent (barbarian_1,barb_control) moveentity barb_body,vec3(0,0.3,0) positionentity barbarian_1,EntityPosition(barb_body) Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
Rick Posted November 18, 2011 Share Posted November 18, 2011 Seems you're still moving the body. If you are using a controller you wouldn't move the body of the model. You would move the controller and then just position your model (not body) to the position of the controller. http://www.leadwerks.com/wiki/index.php?title=Controllers#UpdateController Should give you a pretty good idea of moving the controller. It's been awhile since I've worked with controllers but I think you can PointEntity() on controllers. If not you can just use a pivot and then get the pivots Y value and pass that to the controllers rotation I believe. Just make the pivot follow the controller as well. Quote Link to comment Share on other sites More sharing options...
cassius Posted November 18, 2011 Author Share Posted November 18, 2011 Thanks Rick. I will study this. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
Pixel Perfect Posted November 18, 2011 Share Posted November 18, 2011 You would move the controller and then just position your model (not body) to the position of the controller. This is how I move my NPCs. You can make your model a child of the controller but I wouldn't recommend that as I experienced problems doing it that way. Simply apply a force and direction to the controller and get its new position; then move your model to that position as Rick is suggesting. Quote Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++ Link to comment Share on other sites More sharing options...
cassius Posted November 18, 2011 Author Share Posted November 18, 2011 A code fragment showing this would be usefull if you have time. In c++ or Bmax. But don't worry otherwise. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
Pixel Perfect Posted November 18, 2011 Share Posted November 18, 2011 This is a example taken from a simple NPC class in my (soon to be released) eki-one integration example project : void npc::update(void) { UpdateController(m_NPCController,m_fAngleOfForce,(m_fForce),0,0,15000,1,0); Animate(m_entNPCModel, fmodf(AppTime()/40.0f, (float) m_iCurrentAnimationLength), 1.0f, m_iCurrentSequenceId); PositionEntity(m_entNPCModel, EntityPosition(m_NPCController,1),1); RotateEntity(m_entNPCModel,Vec3(0,getFacingAngle(),0),1); } In this case m_fAngleOfForce and m_fForce are derived elsewhere from a velocity vector passed from the EKI One AI engine (path finding) and the getFacingAngle() function returns the angle the NPC is currently facing; again from the AI engine. In your case you would substitute these values with your own calculated (desired) values. Quote Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++ Link to comment Share on other sites More sharing options...
cassius Posted November 18, 2011 Author Share Posted November 18, 2011 Much apreciated. Thanks to you and Rick. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
cassius Posted November 19, 2011 Author Share Posted November 19, 2011 O got it working. IDidn;t need half the code I I showed you above.I hadn't understood how much controllers take care of. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
Naughty Alien Posted November 19, 2011 Share Posted November 19, 2011 ..small piece of advice, always give some mass to controller...setting it at 0 means it has infinite mass...it will save you from some other problems you may encounter later, if you use it with moving platforms, etc.. Quote Link to comment Share on other sites More sharing options...
cassius Posted November 19, 2011 Author Share Posted November 19, 2011 Is AddbodyForce used to move controllers.? Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
Rick Posted November 19, 2011 Share Posted November 19, 2011 UpdateController() has parameters that move controllers. Physics commands don't work correctly on controllers. Quote Link to comment Share on other sites More sharing options...
cassius Posted November 19, 2011 Author Share Posted November 19, 2011 How do I make my controlled enemy character move toward my main character in a third person game? Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
Rick Posted November 19, 2011 Share Posted November 19, 2011 The most basic way (without pathfinding) is to rotate your enemy controllers toward your main character. Look into PointEntity() to do this rotation. Quote Link to comment Share on other sites More sharing options...
cassius Posted November 20, 2011 Author Share Posted November 20, 2011 At the moment I am using pointentity and moveentity but the character moves in wrong direction. I have heard that you shouldmt use moveentity with controllers but can't see any other way Do I use PointEntity with the controller or the character or both? Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
Rick Posted November 20, 2011 Share Posted November 20, 2011 Look at the UpdateController function. Passing your controllers to this function is how you move controllers. http://www.leadwerks.com/wiki/index.php?title=Controllers#UpdateController One of the parameters to UpdateController is a rotation value. One way to point your enemy to your player is to make a pivot. Assign the position of this pivot to your controller each frame. Then use PointEntity on this pivot to your player. Then in the rotation parameter in UpdateController you can take the Y value of this pivot. So basically you are rotating the pivot along it's Y rotation (as if you were just to turn around in real life) and then taking that Y rotation value and telling your controller to use it as it's rotation. You will also want to set your character model Y rotation value to the same thing each frame so your character will rotation also. Quote Link to comment Share on other sites More sharing options...
cassius Posted November 20, 2011 Author Share Posted November 20, 2011 Thanks Rick. It seems to be working now. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ 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.