Missile control
5 posters
RigidChips :: Rigid-Chips :: Tutorials :: Request a Tutorial
Page 1 of 1
Missile control
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.
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.
Warbird- Tank
- Posts : 60
Join date : 2010-10-27
Age : 29
Location : Germany
Re: Missile control
You can do both.
First, the cross-hair:
_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
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.
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
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
- Posts : 78
Join date : 2010-10-23
Re: Missile control
Fixed a function name for you there, Daniel.
Instead of sqr, you can just use the ^ operator.
Instead of sqr, you can just use the ^ operator.
JHaskly- Admin
- Posts : 235
Join date : 2010-07-16
Age : 28
Location : Brisbane
Re: Missile control
I'm used to programming in C. ^ is xor.
DanielLC- Tank
- Posts : 78
Join date : 2010-10-23
Re: Missile control
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
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
Warbird- Tank
- Posts : 60
Join date : 2010-10-27
Age : 29
Location : Germany
Re: Missile control
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.
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- Walker
- Posts : 382
Join date : 2010-10-11
Age : 29
Location : Brazil
Re: Missile control
_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:
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:
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).
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)
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).
Re: Missile control
thx you really helped me
especially the relative vector is what i´ve been looking for...
especially the relative vector is what i´ve been looking for...
Warbird- Tank
- Posts : 60
Join date : 2010-10-27
Age : 29
Location : Germany
Re: Missile control
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!
*MAD SCIENTIST LAUGHTER*
Thx to all who helped me on this
YOU RULE!!!
... and now I can finally finish my ultra-expic flying aircraftcarrier... with drones!
*MAD SCIENTIST LAUGHTER*
Warbird- Tank
- Posts : 60
Join date : 2010-10-27
Age : 29
Location : Germany
Similar topics
» Harpoon E-1 Guided Missile
» Delta Class Missile Submarine
» Cyclic Control for Helicopters
» Analogue control for your models.
» Time Control Scenario
» Delta Class Missile Submarine
» Cyclic Control for Helicopters
» Analogue control for your models.
» Time Control Scenario
RigidChips :: Rigid-Chips :: Tutorials :: Request a Tutorial
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum