Community

SCI Programming => SCI Community How To's & Tutorials => Topic started by: Cloudee1 on May 20, 2015, 11:51:41 PM

Title: Having a view Orbit another view
Post by: Cloudee1 on May 20, 2015, 11:51:41 PM
So here is another new Class thanks to Phil's work on his decompiler. Having an actor... it may also work with views too I didn't try it because I doubt it, but maybe... orbit around an actor, view, or prop.

First off you will need to add the script to your game. In my case, I have been doing a bit of rearranging so I had script number 982 open. You will want to number your own script accordingly.
Code: [Select]
/******************************************************************************/
(include "sci.sh")
(include "game.sh")
/******************************************************************************/
(script 982)
/******************************************************************************/
(use "Main")
(use "Cycle")
(use "Obj")
/******************************************************************************/
(class Orbit of Motion
    (properties
        client 0
        caller 0
        x 0
        y 0
        dx 0
        dy 0
        {b-moveCnt} 0
        {b-i1} 0
        {b-i2} 0
        {b-di} 0
        {b-xAxis} 0
        {b-incr} 0
        completed 0
        xLast 0
        yLast 0
        centerObj 0
        radius 50
        xTilt 0
        yTilt 0
        angleStep 10
        winding 1
        curAngle 0
    )

    (method (init theClient theCenterObj theRadius theXTilt theYTilt theAngleStep theWinding theCurAngle)
        (var centerObjX, centerObjY, temp2, temp3)
        (if (>= paramTotal 1)
            = client theClient
            (if (>= paramTotal 2)
                = centerObj theCenterObj
                (if (>= paramTotal 3)
                    = radius theRadius
                    (if (>= paramTotal 4)
                        = xTilt theXTilt
                        (if (>= paramTotal 5)
                            = yTilt theYTilt
                            (if (>= paramTotal 6)
                                = angleStep theAngleStep
                                (if (>= paramTotal 7)
                                    = winding theWinding
                                    (if (>= paramTotal 8)
                                        = curAngle theCurAngle
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
        (if (centerObj)
            = centerObjX (send centerObj:x)
            = centerObjY (send centerObj:y)
        )(else
            = centerObjX 160
            = centerObjY 100
        )
        = temp2 SinMult(curAngle radius)
        = temp3 CosMult((+ yTilt global51) CosMult(curAngle radius))
        (if (xTilt)
            = temp2 CosMult(xTilt temp2)
            = temp3 (+ temp3 SinMult(xTilt temp2))
        )
        = x (+ centerObjX temp2)
        = y (- centerObjY temp3)
        = curAngle proc999_1((+ curAngle (* winding angleStep)) 360)
        (super:init(client x y))
    )


    (method (moveDone)
        (self:init())
    )

)

I had to include global51 in the Main script. I am not quite sure yet if that particular global variable has the equivalent already in there.

Also, I already had it in the obj script, but you will probably also need to add in proc_999_1. Just scroll all the way down to the bottom and toss it in there.
Code: [Select]

(procedure public (proc999_1 param1 param2)
    = param1 (- param1 (* param2 (/ param1 param2)))
    (if (< param1 0)
        = param1 (+ param1 param2)
    )
    return param1
)

Ok, so now it is in there so you should be able to make use of this new motion class.

So we will need an instance of an actor added to our game.
Code: [Select]
(instance testerMan of Act(properties x 200 y 90 view 20))

and of course we will actually need to init it. For my test, I just went ahead and had a view 20 orbit around the ego. One thing to note, the orbitting doesn't seem to take place until the actor is basically at the 12:00 position. I started off just placing my testerMan anywhere and he made a straight line to that posn straight north of the orbitee before the orbitting took place. So may as well just init it into that spot.

Code: [Select]
(testerMan:init()
                   posn((send gEgo:x) (- (send gEgo:y) 50))
                   setPri(15)
                   ignoreActors()
                   ignoreControl(ctlWHITE)
                   setCycle(Walk)
                   setMotion(Orbit gEgo)
)

Now looking at the class, there are alot more parameters that can be passed, this was just the bare minimum to get it going...

 theCenterObj // In this case gEgo
 theRadius  // distance from center the points of orbit fall
 theXTilt
 theYTilt
 theAngleStep // number of degrees between points of orbit... setting to 120, orbit forms a triangle. 90 a square
 theWinding  // TRUE or FALSE, setting to 0 the orbiter remains a constant distance, but doesn't circle
 theCurAngle