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] 2

Author Topic: 3d laser beam  (Read 1775 times)

« on: April 10, 2011, 08:49:58 AM »
Hi,
I was wondering if it is possible by script to do the following:
there are two meshes (player and enemy) and one skinmesh (attached to the player mesh) with a solid color texture. On user input the one color skinmesh is stretched towards the enemy model untill it reaches it. This would be a nice way to get a laser beam (I know it can be done by using particles, but I prefer this method).

PS. I can not script, but I do repay by answering other questions. The game I develop will be free for download.
FPS game creator for 3drad and >2000 games GamesAtNight

Akazi14

« Reply #1 on: April 10, 2011, 09:08:37 AM »
I'm with you on that one.
I dont know if it would be possible ???
« Reply #2 on: April 10, 2011, 09:10:38 AM »
I think I have seen skinmesh stretching real time in 3drad before.
FPS game creator for 3drad and >2000 games GamesAtNight

Akazi14

« Reply #3 on: April 10, 2011, 09:12:05 AM »
I think I have seen skinmesh stretching real time in 3drad before.
Yeah, like in the demo projects.
« Reply #4 on: April 10, 2011, 11:37:22 AM »
I think jestermon made something like that once. It was a lazer beam that could be shot and then it would bounce off walls and obstacles.

It's sitting somewhere on the forum, you just have to find it.

The other thing you could do is use the skinmesh spring demo and stretch a skinmesh from the player's weapon to the scan normal (from the scanner object).
« Reply #5 on: April 10, 2011, 01:43:36 PM »
aaah i know jesstermon has done this b4....where two cars were linked by a skinmesh that streched so that it was always linked...im tryna find it now....i know its there tho...
me likes 3drad ;D
« Reply #6 on: April 10, 2011, 01:50:19 PM »
aah found it....the connecting line in this project is a skinmesh
http://www.3drad.com/forum/index.php?topic=5655.0
cheers to jesstermon for answering your question before u even asked it ;D
me likes 3drad ;D
« Reply #7 on: April 10, 2011, 02:03:42 PM »
Look at the ImposterLines demo

It's basicly just

LineDraw(Vector3(x,y,z),Vector3(x,y,z)); use a emissive shader and you have a laser :)
« Reply #8 on: April 11, 2011, 01:52:28 AM »
So, bascly a lot to look into  :P I will have a go at it.
FPS game creator for 3drad and >2000 games GamesAtNight

jestermon

« Reply #9 on: April 11, 2011, 02:36:03 AM »
This post reminded me of a post I did way back when I was doing the Elite project. One of many tests.  perhaps it may be of interest 
It's exactly what Shadmar mentioned.. Orientate object to target, then stretch it on Z the axis. But the imposter line's demo has a neat function for it.

http://www.3drad.com/forum/index.php?topic=3989.msg32013#msg32013

Edit:  Ooops. A year - to within a few days - later, and I see Daniel's point in the same thread, where it was mentioned that "that" specific post be put in a place where it could be found.. I owe you an apology Daniel.. . .with this thread your point is proven.
« Last Edit: April 11, 2011, 03:23:30 AM by jestermon »
« Reply #10 on: April 21, 2011, 11:46:27 AM »
That laser beam does not work with two moving skinmeshes, only with one static. And how do I cange the thickness of the line?
FPS game creator for 3drad and >2000 games GamesAtNight

jestermon

« Reply #11 on: April 21, 2011, 01:19:25 PM »
That laser beam does not work with two moving skinmeshes, only with one static. And how do I cange the thickness of the line?

iObjectScaleSet(OBJ_X,Vector3(width,height,length);  width and height are the thickness.. For a line 2m long, and 0.5 thick use: iObjectScaleSet(OBJ_X,Vector3(0,5, 0.5, 2);
« Reply #12 on: April 21, 2011, 02:11:10 PM »
Thank you Jess, so the code you need is this:
Code: [Select]
int POINTA = OBJ_22;
int POINTB = OBJ_0;
int LINE = OBJ_44;

Vector3 aLoc, bLoc;
Quaternion aRot, bRot;
Quaternion newRot;
float distance;
Vector3 normVec, newVec;
Vector3 normLenVec;

//Returns a lookat quaternion from a to b
Quaternion QuatGetLookAt(Vector3 a, Vector3 b){
   Quaternion orientation;
   Vector3 up = Vector3(0,0,0);
   Vector3 direction = b - a;
   float abx = iFloatAbs(b.x - a.x);
   float aby = iFloatAbs(b.y - a.y);
   float abz = iFloatAbs(b.z - a.z);
   if ((abx < aby) && (abx < abz)) up.x = 1;
   if ((aby < abx) && (aby < abz)) up.y = 1;
   else up.z = 1;
   iQuaternionLookAt(orientation,direction,up);   
   return orientation;
}

void Calc()
{
   iObjectLocation(POINTA, aLoc);
   iObjectLocation(POINTB, bLoc);
   iObjectOrientation(POINTA, aRot);
   iObjectOrientation(POINTB, bRot);
   distance = iVectorLength(bLoc-aLoc);

   //get normal. not used
   iVectorLengthSet(normVec, (bLoc-aLoc),1);
   
   //get normal+length - not used
   iVectorLengthSet(normLenVec, (bLoc-aLoc),distance);
   newVec = normLenVec+aLoc;
 
   //place line
   iObjectScaleSet(LINE, Vector3(5,5,distance));
   iObjectOrientationSet(LINE, QuatGetLookAt(aLoc, bLoc));


   //OUT_132 = dot;
}


void Main()
{
   Calc();
}

Then you need to change the 5, 5 in this line to change the radius of the beam:
Code: [Select]
   //place line
   iObjectScaleSet(LINE, Vector3(5,5,distance));
FPS game creator for 3drad and >2000 games GamesAtNight
« Reply #13 on: April 21, 2011, 02:12:14 PM »
This only leaves me with how to use this code for two moving objects. I need my robot to laser a moving monster.
FPS game creator for 3drad and >2000 games GamesAtNight

jestermon

« Reply #14 on: April 21, 2011, 03:01:00 PM »
yup, the 5,5 will change the thickness.
The placement of the line will depend on the animation you are using.
A laser gun will need the forward vector of the gun barrel, to place the other point of the laser line from the barrel.

You will also need to define
a.. How will you track the monster.
b.. How will you point the gun
c.. When to know that you have hit the monster

If it's a FPS, then a and b are already answered. So you just need to decide how long the line will be, and then use a scanner to see if the monster has been intersected by your line-beam..

Am I on the right track here?

Code: [Select]
///------------------------------------------------------------------
/// Returns a direction vector from an orientation
///------------------------------------------------------------------
Vector3 ForwardVector(Quaternion q)
{
   Vector3 direction;
   iVectorRotate(direction,Vector3(0,0,1),q);
   return direction;
}

1.. Get the forward vector of the gun skinmesh from it's orientation
2.. Set the length of the vector to the length of your beam with iVectorLengthSet() (Store in V2)
3.. Get the location vector of the gun mesh (Store in V1)
4.. Draw your laser beam from V1 to V2

That should do  the trick.
« Last Edit: April 21, 2011, 04:10:56 PM by jestermon »
Pages: [1] 2