3D Rad - Free 3D game maker - Forum

This forum is now archived!

This forum is locked, and is a read-only version. A new community-ran forum can be found at classdev.net

News:

The 3DRad community can be found at classdev.net.

Pages: [1]

Author Topic: Script database  (Read 3750 times)

« on: October 25, 2011, 01:07:01 AM »
Here you can place your script with description for others to use.
FPS game creator for 3drad and >2000 games GamesAtNight
« Reply #1 on: November 05, 2011, 10:23:47 AM »
Quote
float value = 0;
void Main()
{
   if (iKeyDown(iKeyCode("DIK_RETURN"))) value = 0; //This sets 'value' back to zero.
   string text;
   iStringStr(text,value,"%.2f s");
   iObjectTextSet(OBJ_0,text);
   value = value + 0.01;
}

This is time script you have to link textprint to it

   iStringStr(text,value,"%.2f s");  you can set any name of time for eg. coins left or gems needed but you have to edit the script than.

Quote
%.2f s

editing before or after makes you show the name and automaticly sizes it if value is 100 the writing will be moved that 100 would fit

Quote
2F
  are numbers after comma (,)  so you can add 2 3 or none

Quote
%
edit this by putting number before and you will get cool stuff :)
::=::Look at this ::=::
Rally game

The most important thing that happens, you usualy miss it , but after sometime you will remember
 
even if you didint noticed. Go forward and never look back
« Reply #2 on: November 06, 2011, 06:25:03 PM »
Code: [Select]
// This script change the colour of the textprint, is very simple
// You can change the colours: RED, BLUE, GREEN AND THE OPACITY
// Link the script with the textprint.

void Main()
{
   OUT_1 = 0.2;
}
// You can change Out_1:

// OUT_0: Opacity
// OUT_1: Red colour
// OUT_2: Green
// OUT_3: Blue

// 0.2; is the value of the colour or opacity
See my web:
« Reply #3 on: January 27, 2013, 10:49:05 PM »
MouseLook360 steers a Car or PCar with the mouse, even up walls and upside down (physics not included). Like Halo's vehicle steering, but fully 360 capable.

Requires Quaternion_to_cartesian.zip from here for it's RadMath2.dll
If the camera doesn't follow the car, there was a problem loading the dll.

Connect a CamChase 1st, and then a Car or PCar. CamChase should ignore everything. Car or PCar should have it's steering keys disabled. Set forward key to A and reverse to Z, or edit the script's dikAccelerate variable.  (The script will steer opposite if you're going backwards, unless you're throttling forward)

The float bumpyCamReduction should be from 0 (jarring camera motion, but instant look targeting) to 1 (camera doesn't rotate). Closer to 1 reduces jarring, but makes looking sluggish. (A little work still needed here)
Code: [Select]
int objErrorMsg=OBJ_0;
int objCam= OBJ_22;
int objCar= OBJ_44;

///
string dikAccelerate= "DIK_A";
string dikZoomIn= "DIK_PRIOR";
string dikZoomOut="DIK_NEXT";
float bumpyCamReduction= 0.75; // % of what it was, vs. new position. iQuaternionInterpolate

///

Quaternion qCam, qCar;

Hinge h;

// RadMath2.dll can be found in Quaternion_to_cartesian.zip
// Quaternion_to_cartesian.zip can be found here:http://3dfoundry.net/forum/index.php?topic=32.0
int MathDLLHandle=0; // R_atan2 needs RadMath2.dll
void Main() { /// Main
if(iInitializing()) {
MathDLLHandle = iDLLLoad(".\\3DRad_res\\objects\\Script\\RadMath2.dll");
if (MathDLLHandle==0)
         MathDLLHandle = iDLLLoad(".\\3DRad_res\\objects\\Script\\RadMath.dll");

iMouseLookSet(0, 0);
iMouseLookSpeedSet(60, 270);
     
h.init(objCar);
} else if (iDeinitializing()) {
if (MathDLLHandle != 0) iDLLUnload(MathDLLHandle);
} else if (MathDLLHandle != 0) {
iObjectOrientation(objCam, qCam);
iObjectOrientation(objCar, qCar);

mouseLook360();
steerToCamVec();
}
}


/// steerToCamVec

float steerStep=5, steerPos=0;
void steerToCamVec() {
float f= yAngle(qDelta(qCar, qCam));
if ((RelativeSpeed(objCar))<0 and not iKeyDown(iKeyCode(dikAccelerate))) f*=-1;
if (f<steerPos) if (steerPos-f>steerStep) steerPos-=steerStep; else steerPos= f;
if (f>steerPos) if (f-steerPos>steerStep) steerPos+=steerStep; else steerPos= f;
OUT_44= steerPos/IN_45;
}


/// mouseLook360

float dist= 4; // objCam distance from objCar. Initial zoom level
float zStep= 15.0/16.0, wheelFactor=0.75;
void mouseLook360() {
// camera zoom control. Scroll wheel & PgUp/PgDn
float mz= (iMouseZ(true));
if (mz<0) dist/= wheelFactor*zStep; else if (mz>1) dist*= wheelFactor*zStep;
if (iKeyDown(iKeyCode(dikZoomIn))) dist*= zStep;
if (iKeyDown(iKeyCode(dikZoomOut)))  dist/= zStep;

h.update(); // re-align hinge's up direction with the obj's

Quaternion qMouse= qEulers(iMouseLookX(), 2.5*iMouseLookY(), 0);
qCam= qInterpolate(qCam,qMul(qMouse, h.quat),bumpyCamReduction);
// orientation: cam=hinge+mouse

setQuat(objCam, qCam);
setLoc(objCam, getLoc(objCar) + dist*vecRot(qCam, Vector3(0,0.5,-1)));
}

///
/// the brick - shorthand form for nesting expressions
float sign(float f) {return f<0?-1:f>0?1:0;}
float yAngle(Quaternion q) {return yAngle(vecRot(q, Vector3(0,0,1)));}
float yAngle(Vector3 v) {return 57.295779*R_atan2(v.x, v.z);}
Quaternion qDelta(Quaternion q1, Quaternion q2) {return qMul(q1, qInv(q2));} // q1-q2
Quaternion qInv(Quaternion q) {return Quaternion(q.x,q.y,q.z,-q.w);} // -q
Vector3 setLoc(int obj, Vector3 l) {iObjectLocationSet(obj, l); return l;}
Quaternion setQuat(int obj, Quaternion q) {iObjectOrientationSet(obj, q); return q;}
float RelativeSpeed(int obj) {return iVectorDot(vecRot(getQuat(obj), Vector3(0,0,1)), objVelocity(obj));}

/// Simple wrappers that return values instead of setting parameter values
Vector3 vecRot(Quaternion q, Vector3 d) {Vector3 r;iVectorRotate(r,d,q);return r;}
Quaternion qMul(Quaternion q1, Quaternion q2) {Quaternion qt;iQuaternionMultiply(qt,q1,q2);return qt;} // q1+q2
Vector3 getLoc(int obj) {Vector3 l; iObjectLocation(obj, l); return l;}
Quaternion getQuat(int obj) {Quaternion q; iObjectOrientation(obj, q); return q;}
Vector3 objVelocity(int obj) {Vector3 SpeedVec;iObjectVelocity(obj, SpeedVec);return SpeedVec;}
Quaternion qInterpolate(Quaternion q1, Quaternion q2, float q1percent) {Quaternion q;iQuaternionInterpolate(q,q1,q2,q1percent);return q;}
Quaternion qEulers(float x, float y, float z) {Quaternion q;iQuaternionFromEulerAngles(q,x,y,z,"xyz");return q;}
Quaternion qAxisAngle(Vector3 vUp, float dy) {Quaternion q; iQuaternionFromAxisAngle(q, vUp, dy); return q;}

/// requires RadMath2.dll. Returns value1 without it
float R_atan2(float value1, float value2) {
iDLLArraySet(0,value1); iDLLArraySet(1,value2);
iDLLCall(MathDLLHandle,"R_atan2",0);
return iDLLArrayGet(0);
}

///
/// the Hinge rotates it's quat about the object's up(y), but doesn't rotate about it's up axis
class Hinge { // Emmulates Joint:Hinge
int obj; // obj:object to align with
Quaternion quat; // current orientation

// init: specify the object, and aquire it's quat
void init(int obj) {this.quat= getQuat(this.obj=obj);}

// update: re-align with object's up
void update() {
Quaternion qy=getQuat(this.obj);
this.quat= qMul(qy,qAxisAngle(vecRot(qy, Vector3(0,1,0)), yAngle(qDelta(this.quat, qy))));
}
}
(much thanks to Jestermon)
« Last Edit: January 27, 2013, 10:54:29 PM by chronocide »
Pages: [1]