Home   Help Search Login Register  

Author Topic: Problem creating an MG in correct position  (Read 924 times)

0 Members and 1 Guest are viewing this topic.

Offline Bazooka_Boy

  • Members
  • *
  • Proud to be a llama!
    • The Home of DJ Klimax
Problem creating an MG in correct position
« on: 29 Oct 2003, 14:44:28 »
Problem
I'm making my first addon a German machine gun bunker.  As I'm still learning it's just an empty building and I wanted to place an exisiting MG addon.

I've been using And's MG42(bunker) and if I add my bunker and a MG42 to a mission.  Save.  Then edit the mission.sqm, copying the coordinates for the bunker over the top of the coordinates of the MG42.  This works well as I made sure when moddeling my bunker, the coordinates 0,0 of the model were the exact point where the moutning for the MG42 should go.


However as I want my addon to be easy to use I thought it would be easier for the user if they could just call a script from the INIT line of the bunker and have the MG42 created when the mission starts.

I've read some tutorials and plenty of posts in this forum and have got the script working.  Unfortunately although I'm 'getting' the coordinates for the bunker and assigning those as the coordinates to create the MG42 at.  The MG42 is not being created in the correct spot.  It is close to the bunker and by modifying the script  to add values to coordinates I've been able to move it slightly.  But it nevers lines up within the bunker where I want it, it's always outside.

I'm using createVehicle to create the MG42 and have tried another addon but get the same problem.  I'm still a beginer when it comes to scripting but I reported the coordinates of the bunker in a hint box to check what they were.  When I compared these coordinates to the those for the bunker in the mission.sqm I found that they didn't match.

Could someone take a look at my script and config.cpp and see what I'm doing wrong.

It's called from the initialization line of the bunker (named B1) with this line.

[B1] exec "placemg.sqs"

the script

;***************
;**placemg.sqs**
;***************
; Get Name of Bunker (past in init line)
_Object = _this select 0

;Create MG
_Mg1 = "and_WW2mg42b" createVehicle [(getPos _Object select 0)+(0),(getPos _Object select 1)+(0),(getPos _Object select 2)+(0)]  

exit


the config.cpp

/*
  623 by BAZBO 26.09.2003
*/

#define TEast 0
#define TWest 1
#define TGuerrila 2
#define TCivilian 3
#define TSideUnknown 4
#define TEnemy 5
#define TFriendly 6
#define TLogic 7
#define true 1
#define false 0
#define private 0
#define protected 1
#define public 2

class CfgPatches
{
   class BAZBO_BUNKERS
   {
      units[] = {Type 623 MG Bunker};
      weapons[] = {};
      requiredVersion = 1.9;
   };
};

class CfgVehicles
{
    class All {};
     class AllVehicles: All {};
     class Land: AllVehicles {};
     class Static : Land {};
     class Building : Static {};
     class Strategic : Building {};
     class Fortress1 : Strategic {};
     class Fortress2: Fortress1 {};


     class BAZBO_623: Fortress2
    {      
      model="\BAZBO_623\BAZBO_623";
      side=TEast;
      armor=10000;
      scope=2;
      vehicleClass="BAZBO Bunkers";
      displayName="Type 623 MG Bunker";  
    };      
};


I really need to create the MG42 at the exact coordinates that are recorded for the bunker in the mission.sqm

thanks for suggestions
Bazooka_Boy
Bazooka_Boy

If your happy and you know it then your wierd!

Komuna

  • Guest
Re:Problem creating an MG in correct position
« Reply #1 on: 29 Oct 2003, 15:08:24 »
Notice that CamCreate and CreateVehicle create objects at different positions.

What is hapening to you is that your mg is being created at the bunker's positon plus the increment you had in the position array: [(getPos _Object select 0)+(0),(getPos _Object select 1)+(0),(getPos _Object select 2)+(0) ].

So, instead of increasing it, you should decrease it.

However, everytime you change the bunker's direction, you'll get the same problem, as the MG is not being placed at a relative position but at an absolut position. Therefore, trignometry gets in action:

Code: [Select]
_Mg1 = "and_WW2mg42b" createVehicle [(getPos _Object select 0)+cos(getDir _object + 90),(getPos _Object select 1)-sin(getDir _object + 90),(getPos _Object select 2)+(<whatever>)]  
I might have failed the angles, but you'll surely get around that... ;)

Of course, you'll still have to try several times before getting the right pos, but once you've achieved it, it won't fail anymore.
« Last Edit: 29 Oct 2003, 15:10:27 by Komuna »

Offline Bazooka_Boy

  • Members
  • *
  • Proud to be a llama!
    • The Home of DJ Klimax
Re:Problem creating an MG in correct position
« Reply #2 on: 29 Oct 2003, 15:10:41 »
Many thanks for such a quick responce.  I'm off to try that now.

Thanks again
Baz
Bazooka_Boy

If your happy and you know it then your wierd!

Offline Bazooka_Boy

  • Members
  • *
  • Proud to be a llama!
    • The Home of DJ Klimax
Re:Problem creating an MG in correct position
« Reply #3 on: 29 Oct 2003, 16:00:33 »
Tried playing around with that and I'm still not getting it to place correctly.  I'm affraid my maths skills are letting me down today so I'm not understanding the trignometry very well.  I can't remember how sin and cos are used.  I know it's obviously to do with angles relitive to the length of the side of a triangle but can't get past that.

I know by returning the coordinates of the bunker using getPos select 0 > 2 for the three parts of the array and from the coordinates of the bunker in the mission.sqm what the difference is.  Should I be using these figures with the sin and cos to get a relative position to create the mg?

Coordinates returned by getPos

x=3875.33
y=6126.73
z=-0.200001

Coordinates from mission.sqm

   position[]={3876.628174,20.000000,6129.207520};
         special="NONE";
         id=1;
         side="EMPTY";
         vehicle="BAZBO_623";
         leader=1;
         skill=0.600000;
         text="B1";
         init="[B1] exec ""placemg.sqs""";

I think the mission.sqm format is x,z,y so I make the difference

x=-1.298174
y=-2.47752
z=-20.200001

Should I be using these figures somehow?

Baz
Bazooka_Boy

If your happy and you know it then your wierd!

Komuna

  • Guest
Re:Problem creating an MG in correct position
« Reply #4 on: 29 Oct 2003, 17:01:19 »
Well, your method can be pretty effective. However, the z value is surely wrong:

at mission.sqm, the (x,z,y) values regard to the map absolut position. That means that z is the terrain height, according the water level. So, the z value should be anything between 1 and 2 meters, not -20 meters!, of course.

Offline Bazooka_Boy

  • Members
  • *
  • Proud to be a llama!
    • The Home of DJ Klimax
Re:Problem creating an MG in correct position
« Reply #5 on: 29 Oct 2003, 17:49:54 »
A true point about the z value.  I'm leaving it the same as the bunkers and it is showing at teh right height.

  I still can't get the MG close to the right position using my method.  I can't seem to get the MG inside the bunker.  For example the bunker is about 10m wide and if I create the MG with the coordinates from the getPos of the bunker it appears outside the bunker about 2ms to the right and behind the rear left corner.

 If I adjust the coordinates increasing or decreasing either the x or y value by 5m it apears roughly the same distance from one of the other corners of the bunker.  Even though it should be inside the bunker.  Its like it jumps to the other side of the bunker (in the direction of movement) and then moves the extra few metres as I've specified with my

(getPos _Object select 0) +5,

I've found a trigonometry site but i still can't work it out  :(
Bazooka_Boy

If your happy and you know it then your wierd!

Offline Doolittle

  • Contributing Member
  • **
  • _this select 0
Re:Problem creating an MG in correct position
« Reply #6 on: 30 Oct 2003, 19:30:50 »
When you use createVehicle it will never create something inside something else.  Even if you specify the coordinates inside something.  You need to createVehicle and then setPos the vehicle to the coordinates you want....

Doolittle

Offline Bazooka_Boy

  • Members
  • *
  • Proud to be a llama!
    • The Home of DJ Klimax
Re:Problem creating an MG in correct position
« Reply #7 on: 31 Oct 2003, 13:58:11 »
Thanks for the reply Doolittle,  this is starting to make sense to me know.  Thinking about createVehicle as if I was creating a Tank you wouldn't really then create another tank inside the first.

I found a sort of solution by using a trigger to feed the coordinates to the script and then camcreate the MG followed by the bunker (only worked that way round).  But I then had problems using the MG.  I got around this by camcreating a unit as well and issuing the moveInGunner command.

But I think I'll now go back to the createVehicle method and then setPos as you recomend.

Thanks again
Baz
Bazooka_Boy

If your happy and you know it then your wierd!

Offline Doolittle

  • Contributing Member
  • **
  • _this select 0
Re:Problem creating an MG in correct position
« Reply #8 on: 31 Oct 2003, 20:09:15 »
It's also good to createUnit a unit, not camCreate them.

Doolittle

Offline Bazooka_Boy

  • Members
  • *
  • Proud to be a llama!
    • The Home of DJ Klimax
Re:Problem creating an MG in correct position
« Reply #9 on: 01 Nov 2003, 13:33:53 »
Ok thanks, tips like that are always good for us noobs

Baz
Bazooka_Boy

If your happy and you know it then your wierd!