RigidChips
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Missile control

5 posters

Go down

Missile control Empty Missile control

Post by Warbird Mon Nov 08, 2010 8:19 am

So I´ve created an ultra-uber-awesome unfolding missile, but wait: its not a missile- its just a dumb rocket.
But as i haven´t yet learned how to make things fly exactly where i want them to fly to i´ll simply ask now: how can i make my missile fly automatically to a variable coordinate in the world an then detonate? (dont worry about the detonation i already fixed that part with frightening success)
So imagine this: The missile is fired from some random point in the map, it rises, stabilizes and then steers to a point. How can i make the missile do that? Or to be more exactly: how can i make something face towards a point?
But wait, theres more: To know, where im firing at i also need to draw a cross at the point, where the missile will fly to.
confused confused confused

Warbird
Tank
Tank

Posts : 60
Join date : 2010-10-27
Age : 29
Location : Germany

Back to top Go down

Missile control Empty Re: Missile control

Post by DanielLC Mon Nov 08, 2010 3:44 pm

You can do both.

First, the cross-hair:

Code:
_SETCOLOR(255)
_MOVE3D(x+1,y,z)
_LINE3D(x-1,y,z)
_MOVE3D(x,y+1,z)
_LINE3D(x,y-1,z)
_MOVE3D(x,y,z+1)
_LINE3D(x,y,z-1)

_MOVE3D sets a position, and _LIN3D draws from that to another. I'm not entirely sure of how _SETCOLOR works. As it is now, it draws it blue.

Keeping the missile pointed at the right spot is a bit more difficult. First, give a chip in it a name, like N:Chip(name=NAME). From there, you can use stuff like _EX(NAME) to find it's angle.

_EY() gives you the compass heading. Turn so that this is math.sgn(x-_X(NAME))*math.atan((x-_X(NAME))/(y-_Y(NAME))), or the equivalent if you're not using Lua.

_EX() gives you how far you're tilted up and down. It should be math.atan(z-_Z(NAME)/math.sqrt(sqr(x-_X(NAME))+(y-_Y(NAME)))). You'll need to define
Code:
function sqr(x)
  return x*x
end
since it's not an actual function. If you're not using Lua, multiply it by itself. I think there might be some length function you can use to simplify that, but I don't know it.

Finally _EZ() gives you how tilted the missile is. The easy way is to just keep it at 0. The hard way is to use it to figure out what direction each jet actually is facing, as opposed to what it would if it was aligned right and correct for that.

Also, you can use _PLAYERX() etc. to tell where the other guy is, but there's a random error to keep it from being a game breaker.

DanielLC
Tank
Tank

Posts : 78
Join date : 2010-10-23

Back to top Go down

Missile control Empty Re: Missile control

Post by JHaskly Mon Nov 08, 2010 11:28 pm

Fixed a function name for you there, Daniel.

Instead of sqr, you can just use the ^ operator.

JHaskly
Admin

Posts : 235
Join date : 2010-07-16
Age : 28
Location : Brisbane

Back to top Go down

Missile control Empty Re: Missile control

Post by DanielLC Wed Nov 10, 2010 2:53 pm

Really? How do you use xor?

DanielLC
Tank
Tank

Posts : 78
Join date : 2010-10-23

Back to top Go down

Missile control Empty Re: Missile control

Post by JHaskly Wed Nov 10, 2010 11:31 pm

Hmm?

JHaskly
Admin

Posts : 235
Join date : 2010-07-16
Age : 28
Location : Brisbane

Back to top Go down

Missile control Empty Re: Missile control

Post by DanielLC Thu Nov 11, 2010 6:12 pm

I'm used to programming in C. ^ is xor.

DanielLC
Tank
Tank

Posts : 78
Join date : 2010-10-23

Back to top Go down

Missile control Empty Re: Missile control

Post by bwansy Thu Nov 11, 2010 11:11 pm

In Lua, ^ is the exponentiation operator.

bwansy
Admin

Posts : 170
Join date : 2010-07-15

https://rigidchips.forumotion.com

Back to top Go down

Missile control Empty Re: Missile control

Post by JHaskly Thu Nov 11, 2010 11:45 pm

How odd Laughing

JHaskly
Admin

Posts : 235
Join date : 2010-07-16
Age : 28
Location : Brisbane

Back to top Go down

Missile control Empty Re: Missile control

Post by Warbird Wed Dec 01, 2010 9:37 am

ok sounds good but im not familiar with lua.
do you know how to do it with a simple script? I´ve used functions like TODEG_AZ / _AX and some other ones before to stabilize the missile so this part is fine but the direction control for targeting and flying towards other players is still malfunctioning so I could use some help with that.
Thanks anyway for your kind help Very Happy

Warbird
Tank
Tank

Posts : 60
Join date : 2010-10-27
Age : 29
Location : Germany

Back to top Go down

Missile control Empty Re: Missile control

Post by RA2lover Wed Dec 01, 2010 10:07 am

the pointer for other players is _PLAYERX(n),_PLAYERY(n) and _PLAYERZ(n)
where n is the player number.

you'll need to convert that to an angle relative to your position and get the missile to point to it.
RA2lover
RA2lover
Walker
Walker

Posts : 382
Join date : 2010-10-11
Age : 29
Location : Brazil

Back to top Go down

Missile control Empty Re: Missile control

Post by bwansy Wed Dec 01, 2010 11:20 am

_AX/_AZ are good for autopilots (e.g. level flight, level turn), but not really useful for missile controls.

RA2lover is right, you have to convert the target's position relative to the missile into angles. To do this first you must be familiar with conversion between inertial (world) vectors into body (local) vectors.

First step: get the relative position a.k.a. displacement vector
To do this, you must specify the reference chip, which is used to represent the missile as a whole. It would be best to choose a chip close to the C.G. of the missile that faces the same direction as the missile's direction of flight (facing the "right" way).
To get the displacement vector:
Code:
dx = _PLAYERX(n)-_X(chip)
dy = _PLAYERY(n)-_Y(chip)
dz = _PLAYERZ(n)-_Z(chip)

Second step: convert into local vector
Since this displacement vector was in world frame (both the locations of your missile and the target are based on the map's coordinates), we need to convert into local vector (looking from the missile's perspective). This requires some matrix operation. If you don't know what it is, don't panic. Just do the following:
Code:
bdx = dx*_XX(chip)+dy*_XY(chip)+dz*_XZ(chip)
bdy = dx*_YX(chip)+dy*_YY(chip)+dz*_YZ(chip)
bdz = dx*_ZX(chip)+dy*_ZY(chip)+dz*_ZZ(chip)
This would be the relative position in local frame.

Third step: convert this vector into relative pitch and yaw angles:
This step requires some basic trig functions in 3D. Assuming that you are using a chip that has the "right" orientation (see step 1), then its -Z axis would be pointing forward, +Y axis upward, and +X axis to the left.
Relative pitch angle (in radians) would simply be atan(bdy/-bdz) (notice the negative sign, since forwards is the negative Z axis), where positive angle = upward pitch; relative yaw would be asin(bdx/(sqrt(bdy^2+bdz+2)), where positive angle = left.

Finally, use these angles to control your missile's elevators and rudders (or whatever pitch/yaw controls you have).

bwansy
Admin

Posts : 170
Join date : 2010-07-15

https://rigidchips.forumotion.com

Back to top Go down

Missile control Empty Re: Missile control

Post by Warbird Wed Dec 01, 2010 2:22 pm

thx you really helped me Very Happy
especially the relative vector is what i´ve been looking for...

Warbird
Tank
Tank

Posts : 60
Join date : 2010-10-27
Age : 29
Location : Germany

Back to top Go down

Missile control Empty Re: Missile control

Post by Warbird Thu Dec 02, 2010 11:35 am

Check this out: https://rigidchips.forumotion.com/works-in-progress-f20/harpoon-e-1-guided-missile-t127.htm#1138

Thx to all who helped me on this

YOU RULE!!!

... and now I can finally finish my ultra-expic flying aircraftcarrier... with drones!

Very Happy Very Happy Very Happy

*MAD SCIENTIST LAUGHTER*

Warbird
Tank
Tank

Posts : 60
Join date : 2010-10-27
Age : 29
Location : Germany

Back to top Go down

Missile control Empty Re: Missile control

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum