Author Topic: E2 - orbiting ship  (Read 11870 times)

kevinminion

  • Global Moderator
  • Full Member
  • *****
  • Posts: 147
  • Karma: +15/-0
    • View Profile
  • IGN: Kevin Minion
E2 - orbiting ship
« on: June 17, 2017, 07:47:21 pm »
I'd like to have a chip that will allow my ship to orbit a planet.  Possibly using the aimVector and a low MaxKPH on my gyro pod.   Open to other solutions as well, I may be thinking about this all wrong, thus making it overly complex.

Assuming I know the planet center location and the radius:
  Maintain a Z value of planet center + 1/2 radius
  Maintain an orbit the same radius as the planet
  I would think calculating the correct yaw angle and then going "Forward" would be easiest, but I'm not sure how to make that into the AimVec for the gyropod input.
 
Thanks for any help in anvance...

bloxgate

  • Supreme Forum Overlord
  • Administrator
  • Hero Member
  • ******
  • Posts: 546
  • Karma: +50/-4
    • View Profile
    • Bloxgate's Website
  • IGN: bloxgate
Re: E2 - orbiting ship
« Reply #1 on: June 17, 2017, 09:44:25 pm »
X_1 = X_0 + Z\cos(\theta + \Delta \theta)
Y_1 = Y_0 + Z\sin(\theta + \Delta \theta)
\Delta\theta = \frac{2\pi Z}{t}

See: https://gamedev.stackexchange.com/questions/9607/moving-an-object-in-a-circular-path
« Last Edit: June 17, 2017, 09:49:48 pm by bloxgate »

kevinminion

  • Global Moderator
  • Full Member
  • *****
  • Posts: 147
  • Karma: +15/-0
    • View Profile
  • IGN: Kevin Minion
Re: E2 - orbiting ship
« Reply #2 on: June 18, 2017, 04:33:17 pm »
Moving a holo entity around using setPos using equations like this is a bit easier...


I'm trying to figure out how to control a gyropod to orbit the planet in a similar fashion.


RendStung

  • Starting Member
  • *
  • Posts: 44
  • Karma: +1/-0
    • View Profile
  • IGN: RendStung
Re: E2 - orbiting ship
« Reply #3 on: June 18, 2017, 04:41:39 pm »
It's simple, make it go up and set AimPos to the center of the planet.
Just call me Rend. DO NOT CALL ME STUNG WHATEVER YOU DO!

kevinminion

  • Global Moderator
  • Full Member
  • *****
  • Posts: 147
  • Karma: +15/-0
    • View Profile
  • IGN: Kevin Minion
Re: E2 - orbiting ship
« Reply #4 on: June 18, 2017, 06:23:07 pm »
To circle/orbit a target I would set the AimVec to the target's position and MoveLeft/Right or MoveUp/Down.  That is a pretty standard practice, even from the years of NightHawk. 
However, I would like my ship's facing direction to maybe be 90° offset (normal) of the vector of the orbit center and the ship.

bloxgate

  • Supreme Forum Overlord
  • Administrator
  • Hero Member
  • ******
  • Posts: 546
  • Karma: +50/-4
    • View Profile
    • Bloxgate's Website
  • IGN: bloxgate
Re: E2 - orbiting ship
« Reply #5 on: June 18, 2017, 08:51:48 pm »
Use the equations I posted to find the next position, then use the gyropods autopiloting to move it to that location?

kevinminion

  • Global Moderator
  • Full Member
  • *****
  • Posts: 147
  • Karma: +15/-0
    • View Profile
  • IGN: Kevin Minion
Re: E2 - orbiting ship
« Reply #6 on: June 19, 2017, 02:28:01 am »

What is it doing?
The gyro flies the ship out to an (x,y) point on the orbit (XYLock)
At the same time, it tries to find the correct altitude (ZLock)

Once this is complete, it tries to maintain a clockwise orbit (from above) by adjusting the pointing direction with Yaw and the distance from the planet with MoveRight

Disclaimer: It's version 1.0!
This isn't pretty, but it works (most of the time)
Multipliers are set low to keep the gyro from spazzing (most of the time)


Code: [Select]
@name Blox_Orbiting_e2_v1.0
# Created by KevinMinion

@inputs Gyro:wirelink EGP:wirelink
@outputs
@persist Closest:entity ClosestPos:vector ClosestRad
@persist X1 Y1 Z1
@persist XYLock ZLock StartOrbit
@trigger

# Weld this E2 to the gyropod
# The EGP input is not required

if (first() | dupefinished()) {

    EGP:egpClear()

    GyroPod = entity():isWeldedTo()

    Gyro = GyroPod:wirelink()

    findByClass("logic_case*")
    findSortByDistance( entity():pos() )
   
    Closest = find()

    ClosestPos = floor( Closest:pos() )
    ClosestRad = getPlanetRadius(Closest)

    hint("Orbiting: " + getPlanetName(Closest),10)
   
    K=1
    EGP:egpText(K,"[X0: " + ClosestPos:x() + "]", vec2(220,300) )
   
    K++
    EGP:egpText(K,"[Y0: " + ClosestPos:y() + "]", vec2(220,320) )
   
    K++
    EGP:egpText(K,"[Z0: " + ClosestPos:z() + "]", vec2(220,340) )
   
    K++
    EGP:egpText(K,"[R0: " + ClosestRad + "]", vec2(220,360) )
   
   
   
    K++
    X1 = ClosestPos:x() + ClosestRad
    EGP:egpText(K,"[X1: " + X1 + "]", vec2(220,400) )
   
    K++
    Y1 = ClosestPos:y() + ClosestRad
    EGP:egpText(K,"[Y1: " + Y1 + "]", vec2(220,420) )
   
    K++
    Z1 = ClosestPos:z() + (ClosestRad * 0.75)
    EGP:egpText(K,"[Z1: " + Z1 + "]", vec2(220,440) )


    Gyro["MPH Limit",number] = 5

    XYLock = 0
    ZLock = 0
    StartOrbit = 0
}



K=20
K++
EGP:egpText(K,"[EX: " + floor(entity():pos():x()) + "]", vec2(220,500) )

K++
EGP:egpText(K,"[EY: " + floor(entity():pos():y()) + "]", vec2(220,520) )

K++
EGP:egpText(K,"[EZ: " + floor(entity():pos():z()) + "]", vec2(220,540) )

K++
ED = floor(vec2(X1,Y1):distance2(vec2(entity():pos():x(), entity():pos():y())))
EGP:egpText(K,"[ED: " + ED + "]", vec2(220,560) )



if ( (ED > 5000) & (!XYLock) ) {

    Gyro["AimVec",vector] = vec(X1,Y1,Z1)
    Gyro["AimMode",number] = 1
    Gyro["Forward",number] = 1

    K++
    EGP:egpText(K,"XY: Locking", vec2(220,600) )
    EGP:egpColor(K,vec(255,0,0))   
   
    XYLock = 0   
   
} else {

    Gyro["AimMode",number] = 0
    Gyro["Forward",number] = 0

    K++
    EGP:egpText(K,"XY: Locked", vec2(220,600) )     
    EGP:egpColor(K,vec(0,255,0))   
   
    XYLock = 1

}   




if (entity():pos():z() < (Z1 - 50)) {
    Gyro["MoveUp",number] = 1
    Gyro["MoveDown",number] = 0
    Gyro["Level",number] = 1

    K++
    EGP:egpText(K,"Z: Locking", vec2(220,620) )
    EGP:egpColor(K,vec(255,0,0))   
   
    ZLock = 0

} elseif  (entity():pos():z() > (Z1 + 50)) {
    Gyro["MoveDown",number] = 1
    Gyro["MoveUp",number] = 0
    Gyro["Level",number] = 1

    K++
    EGP:egpText(K,"Z: Locking", vec2(220,620) )
    EGP:egpColor(K,vec(255,0,0))   

    ZLock = 0

} else {
    Gyro["MoveUp",number] = 0
    Gyro["MoveDown",number] = 0
    Gyro["Level",number] = 0
   
    K++
    EGP:egpText(K,"Z: Locked", vec2(220,620) )
    EGP:egpColor(K,vec(0,255,0))

    ZLock = 1

}


if (XYLock & ZLock) {

    StartOrbit = 1
   
    Gyro["Level",number] = 1
   
}


Bearing = entity():bearing(vec(ClosestPos:x(),ClosestPos:y(),entity():pos():z()))
Distance = entity():pos():distance(vec(ClosestPos:x(),ClosestPos:y(),entity():pos():z()))

K++
EGP:egpText(K,"Bearing to planet center: " + floor(Bearing), vec2(220,660) )

K++
EGP:egpText(K,"Distance to planet center: " + floor(Distance), vec2(220,680) )


if (StartOrbit) {

    interval(100)

    Gyro["Forward",number] = 1
    Gyro["YawMult",number] = 0.2
   

    if (Bearing >= 0) {
        if (Bearing < 90) {
            Gyro["YawLeft",number] = 0
            Gyro["YawRight",number] = 1
        } else {
            Gyro["YawLeft",number] = 1
            Gyro["YawRight",number] = 0
        }

        if (Distance > (ClosestRad + 500)) {
            Gyro["MoveLeft", number] = 0
            Gyro["MoveRight", number] = 1
        } elseif (Distance < (ClosestRad - 500)) {
            Gyro["MoveLeft", number] = 1
            Gyro["MoveRight", number] = 0
        } else {
            Gyro["MoveLeft", number] = 0
            Gyro["MoveRight", number] = 0
        }   
       
    } else {
        if (Bearing > -90) {
            Gyro["YawLeft",number] = 0
            Gyro["YawRight",number] = 1
        } else {
            Gyro["YawLeft",number] = 1
            Gyro["YawRight",number] = 0
        }
    }


} else {
       
    interval(2000)

}