DWORD Posted April 29, 2010 Share Posted April 29, 2010 Hello. I'm new with LW engine(and here). I'm just messing around with the engine to learn. I just built a top-down (simple) game with a player that look at the cursor but isn't accurate for isometric views( is perfectly good in 2.5d shooters and top-down view). Engine engine; Mouse m; float res = 0; int xw = 0, yh = 0, result = 0; //X if(m.GetX() > engine.GetWidth()/2) { xw = -((engine.GetWidth()/2)-m.GetX()); } else { if(m.GetX() < engine.GetWidth()/2) { xw = -((engine.GetWidth()/2)-m.GetX()); } else { xw = 0; } } //Y if(m.GetY() > engine.GetHeight()/2) { yh = ((engine.GetHeight()/2)-m.GetY()); } else { if(m.GetY() < engine.GetHeight()/2) { yh = ((engine.GetHeight()/2)-m.GetY()); } else { yh = 0; } } //Set the angle if(yh > 0 && xw == 0) { result = 90; } else if(yh < 0 && xw == 0) { result = 270; } else if(xw > 0 && yh == 0) { result = 0; } else if(xw < 0 && yh == 0) { result = 180; } else if(xw == 0 || yh == 0) { result = 0; } else { res = (float)yh/xw; result = (atan(res) * 45) / 0.785398163; } //Correct the angle if(result < 0) { result = -result; } if(xw < 0 && yh > 0) { result = (90-result)+90; } else if(xw < 0 && yh < 0) { result = 180+result; } else if(xw > 0 && yh < 0) { result = (90-result)+270; } As you see is really messy(the rest of the code is worse ). To use this you have to set rotation of your entity(Y axis) to "result" like this "YourEntity.SetRotation(Vec3(0,result,0));". So have another way to do this? Thanks. Sorry about my english. Quote Link to comment Share on other sites More sharing options...
ZioRed Posted April 29, 2010 Share Posted April 29, 2010 I'm not sure to have understood correctly your question, but if you have to face a model towards another one I think the easier way is with PointEntity? You may create a Pivot and move it together with your mouse move coordinates (may be X and Z), then call PointEntity from your character mesh to the pivot. 2 Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
DWORD Posted April 29, 2010 Author Share Posted April 29, 2010 I'm not sure to have understood correctly your question, but if you have to face a model towards another one I think the easier way is with PointEntity? You may create a Pivot and move it together with your mouse move coordinates (may be X and Z), then call PointEntity from your character mesh to the pivot. Really thanks, i didn't knew about this Pivot Quote 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.