Jump to content

brainlid

Community Newbie
  • Posts

    2
  • Joined

  • Last visited

brainlid's Achievements

Tiro

Tiro (1/14)

0

Reputation

  1. Thanks for the information. If I can get it working as a proof of concept then I'd love help refactoring it to use vectors. Not a strength for me. Thanks, -Mark E
  2. I'm new to the forum and to hacking on 0 a.d. Currently I'm experimenting with different unit movement logic. My trig math skills are too weak to get me through this. Also, I'm just too inexperienced with the code to make this work. Instead of using the formation logic of offsets, I want to write more dynamic simulation-like behaviors. This is a fun experiment for me that I've been wanting to do for a while now. Specific Question: ===== Given a unit with a starting position and direction/angle, how do I project to a point along that angle to be a distance of 20 units away? I understand the math formula used to do this, but when it comes down to radians, negative angles/quadrant, game's coordinate system, etc. I get all confused. Here's some example code: (/simulation/components/UnitAI.js) var formationTarget = this.order.data; // Loop through each member of formation and apply the behavior for each (var ent in cmpFormation.members) { var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); var entPos = Engine.QueryInterface(ent, IID_Position); if (!entPos || !entPos.IsInWorld()) continue; var pos = entPos.GetPosition(); // // do stuff that modifies desired direction to take from here // // Project new target point to move towards. var distanceAway = 20; var x = pos.x + (distanceAway * Math.cos(angle)); var z = pos.z + (distanceAway * Math.sin(angle)); // Move unit towards the new point cmpUnitAI.MoveToPoint(x, z); } I'm getting an angle like -1.5 which I don't know what to do with. The units are moving but more eradic and seemingly unrelated to the command location that the direction is based on. I'm pretty sure my math skills are to blame. Would really appreciate any help. -Mark E
×
×
  • Create New...