View topic - Unit facing direction

 All times are UTC + 1 hour

 Page 1 of 1 [ 12 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Unit facing directionPosted: 27 Oct 2009, 19:41

Joined: 14 Aug 2008, 20:54
 Part of my AI's formations logic will need to determine a unit's facing direction (as well as the need to face units in a certain direction).I'd hate to think that the only way to 'face' a unit in a particular direction was to create a bogus move command and then stop the unit once movement starts (heck, tanks can turn in place pretty easily).Is there any way to determine the 'direction' a unit is facing (radians? degrees? cardinal direction?)? (other than tracking previous movements and extrapolating based on straight line analysis?) Is there any way to 'face' a unit in a particular direction without crazy unnecessary movements?I am assuming that units can 'fire' in any direction regardless of what direction the vehicle is facing?Can any BA units turn in place or is the 'turn rate' for each unit involved?

 Post subject: Re: Unit facing directionPosted: 27 Oct 2009, 20:24
 Spring Developer

Joined: 08 Oct 2006, 15:58
 Quote:Is there any way to determine the 'direction' a unit is facing (radians? degrees? cardinal direction?)? (other than tracking previous movements and extrapolating based on straight line analysis?)No.Quote:Is there any way to 'face' a unit in a particular direction without crazy unnecessary movements?No.Quote:I am assuming that units can 'fire' in any direction regardless of what direction the vehicle is facing?Depends on a unit's armament (weapon aiming restrictions, etc), but true for many *A units.Quote:Can any BA units turn in place or is the 'turn rate' for each unit involved?All unit types can perform in-place turns below a certain limit (which defaults to 15 elmos per second; AI's can not read the actual value), but this only kicks in when a unit's turning speed is less than its wanted speed.

 Post subject: Re: Unit facing directionPosted: 27 Oct 2009, 22:02

Joined: 14 Aug 2008, 20:54
 Quote:No.Grumble.Just a little more work for me.

 Post subject: Re: Unit facing directionPosted: 27 Oct 2009, 22:12
 Spring 1944 Developer

Joined: 11 Oct 2005, 06:18
Location: Ukraine
 I had to code my own 'turn in place' command for Spring 1944 units in lua. Spring engine isn't really suited for non-360 degree turreted weapons (or at least their support is far from perfect), as well as some other features not usually found in *A mods.My solution can be extended to other games/mods, but that requires changes to those mods, which no AI should do, so it's hardly of use here (unless some engine dev implements a similar feature into Spring itself).

 Post subject: Re: Unit facing directionPosted: 27 Oct 2009, 22:32

Joined: 14 Aug 2008, 20:54
 thanks....I'll be ok I think.

 Post subject: Re: Unit facing directionPosted: 29 Oct 2009, 07:49

Joined: 14 Aug 2008, 20:54
 Quote:All unit types can perform in-place turns below a certain limit (which defaults to 15 elmos per second; AI's can not read the actual value), but this only kicks in when a unit's turning speed is less than its wanted speed.Can you elaborate on this?Between all these functions, I figured I should be able to get arbitrary units to 'turn in place' or at leas move in a minimal direction enough to face the direction of movement when complete (dynamically based on unitDef)getTurnInPlaceDistance() Units above this distance to goal will try to turn while keeping some of their speed.getTurnInPlaceSpeedLimit() Units below this speed will turn in place regardless of their turnInPlace setting.getTurnRadius() getTurnRate() I've tried changing wanted speed to match at/below/above the turninplace speed limit (with little/no effect), tried various distances for movement but each unit requires unique values....Any ideas?

 Post subject: Re: Unit facing directionPosted: 29 Oct 2009, 12:51
 Spring Developer

Joined: 01 Jun 2005, 10:36
Location: The Netherlands
 I recall I experimented some time with a nearby (say 100 elmos or so) CMD_MOVE plus a CMD_SET_WANTED_MAX_SPEED very close to zero (0.001 or so), and IIRC this worked decently to turn a unit while keeping it almost in same place.Note the move command needs to be far enough away from the unit or it will think it has reached it's destination already and it will stop. Also it needs small but non-zero wanted max speed IIRC, or the unit just won't move/turn at all.

 Post subject: Re: Unit facing directionPosted: 29 Oct 2009, 14:08

Joined: 14 Aug 2008, 20:54
 Thanks...I will try this tonight. I did not experiment with wanted speeds that low....I apologize...can somebody give me a rundown on the term 'elmo'? Elmos as a rate means to me 'how many Elmo's big bird can eat per second...which is about 2.4'

 Post subject: Re: Unit facing directionPosted: 29 Oct 2009, 15:58
 Spring Developer

Joined: 01 Jun 2005, 10:36
Location: The Netherlands
 It's the semi official unit of measurement used for distances in Spring.1 elmo = 1 map texture pixel = 1/8 map heightmap pixelsCoordinates for commands, unit positions, etc., all are measured in 'elmos'.

 Post subject: Re: Unit facing directionPosted: 30 Oct 2009, 12:18

Joined: 14 Aug 2008, 20:54
 Got it to work. Pretty nifty. Thanks much!!Code:    private void rotateUnit(COCUnit unit, float angle){        float DISTANCE=100f;        float SPEED = 0.002f;        float toX = (float)Math.cos(Math.toRadians(angle))*DISTANCE;        float toZ = -(float)Math.sin(Math.toRadians(angle))*DISTANCE;        float toY = unit.getUnit().getPos().y;        AIFloat3 moveTo = new AIFloat3(unit.getUnit().getPos().x+toX, toY, unit.getUnit().getPos().z+toZ);        AICommand command = new MoveUnitAICommand(unit.getUnit(), 0,new java.util.ArrayList(), 1000, moveTo);        handleEngineCommand(command);        command = new SetWantedMaxSpeedUnitAICommand(unit.getUnit(), 0,new java.util.ArrayList(), 1000, SPEED );        handleEngineCommand(command);    }

 Post subject: Re: Unit facing directionPosted: 30 Oct 2009, 19:32
 Kernel Panic Co-Developer

Joined: 16 Nov 2004, 13:08
 You must mean 1/8, not 8.

 Post subject: Re: Unit facing directionPosted: 31 Oct 2009, 11:47
 Spring Developer

Joined: 01 Jun 2005, 10:36
Location: The Netherlands
 Ah, yes, thanks, fixed now.

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 12 posts ]

 All times are UTC + 1 hour

#### Who is online

Users browsing this forum: No registered users and 2 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ Spring    Community News       News Submissions    General Discussion    Help & Bugs    Game Lobby       Spring Clans       Lobby Clients    Tournaments    Linux    Mac OS X    Off Topic Discussion Content Creation    Game Development       Game Development Tutorials & Resources    Map Creation       Map Tutorials & Resources    Art & Modelling       Modelling & Texturing Tutorials & Resources    Project Subforums       Kernel Panic       Zero-K       Balanced Annihilation       Spring: 1944       Star Wars: Imperial Winter       XTA       Supreme Annihilation       Caydr's Projects       Evolution RTS       Argh's Projects       The Cursed       NOTA       Damned       Conflict Terra       Engines Of War       Spring Tanks       Journeywar       BattleTech: Legacy       Dune: Evolution       Progressive Annihilation       TA: Factions    Sound Effects & Music Development    News    Development       Dedicated Developer Discussion       New Developer Discussion       Infrastructure Development       Meeting Minutes    AI    Feature Requests    Lua Scripts       The Werewolf Game Site content    Site content       Banners       Welcome images       Videos       Videos - contributions       Screenshots       Screenshots - contributions