Welcome Guest [Log In] [Register]
We hope you enjoy your visit.


You're currently viewing the Ultimate 3D Community as a guest. This means that you can only read posts, but can not create posts or topics by yourself. To be able to post you need to register. Then you can participate in the community active and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.

Join our community!

If you are already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
x,y,z for a ray
Topic Started: Nov 22 2010, 01:04 AM (403 Views)
DJ-Habana
C# King
[ *  *  *  *  *  * ]
How can I get the x y z from a ray
All I know is it is something like this

Dist=CheckRayIntersection(terrain,x,y,z+height,Longi,Lati,0);
//...and if it is, calculate the coordinates of the point under the mouse
//cursor
if (Dist < 90000)
{

CalculateVectorScalarProduct(#####,Vect,Dist);
^^^^ dunno what should come there
//retrieve the coordinates of the point under the cursor
X=GetVector(Vect,1)+x;
Y=GetVector(Vect,2)+y;
Z=GetVector(Vect,3)+z+height;

}
Posted Image


Offline Profile Quote Post Goto Top
 
Dr. Best
Member Avatar
Administrator
[ *  *  *  *  *  * ]
You can either use CreateDirectionVector(...) among with GetVector(...) or you can use the code from the Move(...) script.
Offline Profile Quote Post Goto Top
 
DJ-Habana
C# King
[ *  *  *  *  *  * ]
ok thanx this is the code I should use then I think:

Dist=CheckRayIntersection(terrain,x,y,z+height,Longi,Lati,0);
CreateDirectionVector(InputVect,roty,rotx)
if (Dist < 90000)
{
CalculateVectorScalarProduct(InputVect,Vect,Dist);
X=GetVector(Vect,1);
Y=GetVector(Vect,2);
Z=GetVector(Vect,3);
}

what I want to do is bassicly find the x y and z where the camera is aiming and then let the character creates a direction from
his x,y,z to X,Y,Z
in order for a more acurate shooting when a character shoots because now I am aiming at a point but the bullet doesn't hit where I aim
Posted Image


Offline Profile Quote Post Goto Top
 
Dr. Best
Member Avatar
Administrator
[ *  *  *  *  *  * ]
Be aware that you need to add the ray origin to this offset vector, otherwise it is relative to that. Other than that your code looks good. But in some version I made CheckRayIntersection(...) return -1, if the ray does not intersect anything. You may want to check, whether your code handles that correctly.
Offline Profile Quote Post Goto Top
 
DJ-Habana
C# King
[ *  *  *  *  *  * ]
ok ill just make use of an if- that might work. ok let me go test it
jee I can't remember how would I point the roty and rotx from
x,y,z to X,Y,Z
Edited by DJ-Habana, Nov 22 2010, 11:00 PM.
Posted Image


Offline Profile Quote Post Goto Top
 
DJ-Habana
C# King
[ *  *  *  *  *  * ]
Got This error
something about vector id 0


here is my current code:

Code:
 

if can_fire=true
{
Dist=CheckRayIntersection(u3d_floor,x,y,z+height,camera.roty,camera.rotatex,0);
InputVect = CreateVector();
Vect = CreateVector();
CreateDirectionVector(InputVect,camera.roty,camera.rotatex)
if (Dist < 90000)
{
CalculateVectorScalarProduct(InputVect,Vect,Dist);
X=GetVector(Vect,1);
Y=GetVector(Vect,2);
Z=GetVector(Vect,3);
}

ReleaseVector(InputVect);
ReleaseVector(Vect);

sendBull();
bulroty = point_direction(x,y,X,Y);
Createbullet(x,y,z,bulroty,shoot_rotx);
can_fire=false;
alarm[0]=6;
Attached to this post:
Attachments: Untitled.jpg (37.8 KB)
Edited by DJ-Habana, Nov 22 2010, 11:36 PM.
Posted Image


Offline Profile Quote Post Goto Top
 
Dr. Best
Member Avatar
Administrator
[ *  *  *  *  *  * ]
You need to initialize vectors by passing -1 for the output vector ID parameter. The functions return the vector ID then. Lateron you need to call ReleaseVector(...) to get rid of the vectors again.
Offline Profile Quote Post Goto Top
 
DJ-Habana
C# King
[ *  *  *  *  *  * ]
ok I tried doing this now:

Dist=CheckRayIntersection(u3d_floor,x,y,z+height,camera.roty,camera.rotatex,0);
Vect = -1;
InputVect = -1;
CreateVector(InputVect);
CreateVector(Vect);
CreateDirectionVector(InputVect,camera.roty,camera.rotatex)
if (Dist < 90000)
{
CalculateVectorScalarProduct(InputVect,Vect,Dist);
X=GetVector(Vect,1);
Y=GetVector(Vect,2);
Z=GetVector(Vect,3);
}

sendBull();
bulroty = point_direction(x,y,X,Y);
Createbullet(x,y,z,bulroty,shoot_rotx);

ReleaseVector(InputVect);
ReleaseVector(Vect);
can_fire=false;
alarm[0]=6;

but now it is shooting but not in the direction, it only shoots in one direction
Posted Image


Offline Profile Quote Post Goto Top
 
Dr. Best
Member Avatar
Administrator
[ *  *  *  *  *  * ]
Correctly it goes like this:
Code:
 
InputVect=CreateDirectionVector(-1,camera.roty,camera.rotatex);
// ... Do something with the vector
ReleaseVector(InputVect);
Offline Profile Quote Post Goto Top
 
DJ-Habana
C# King
[ *  *  *  *  *  * ]
Ok so then I must still do something wrong.
Code:
 

Vect = -1 // If I take this out it doesn't work if it is not taken out then the bullet doesn't go where I aim
Dist=CheckRayIntersection(u3d_floor,x,y,z+height,camera.roty,camera.rotatex,0);
InputVect=CreateDirectionVector(-1,camera.roty,camera.rotatex);
if (Dist>0) && (Dist<90000)
{
CalculateVectorScalarProduct(InputVect,Vect,Dist);
X=GetVector(Vect,1);
Y=GetVector(Vect,2);
Z=GetVector(Vect,3);
}
ReleaseVector(InputVect);
ReleaseVector(Vect);
bulroty = point_direction(x,y,X,Y)
//bullrotx = //still searching for my code to point in the rotx direcion where the camera aims at
sendBull();
Createbullet(x,y,z,bulroty,shoot_rotx);
can_fire=false;
alarm[0]=6;
Posted Image


Offline Profile Quote Post Goto Top
 
Dr. Best
Member Avatar
Administrator
[ *  *  *  *  *  * ]
Try this:
Code:
 
Dist=CheckRayIntersection(u3d_floor,x,y,z+height,camera.roty,camera.rotatex,0);
InputVect=CreateDirectionVector(-1,camera.roty,camera.rotatex);
if (Dist>0) && (Dist<90000)
{
CalculateVectorScalarProduct(InputVect,InputVect,Dist);
X=GetVector(InputVect,1);
Y=GetVector(InputVect,2);
Z=GetVector(InputVect,3);
}
ReleaseVector(InputVect);
bulroty = point_direction(x,y,X,Y)
//bullrotx = //still searching for my code to point in the rotx direcion where the camera aims at
sendBull();
Createbullet(x,y,z,bulroty,shoot_rotx);
can_fire=false;
alarm[0]=6;
Offline Profile Quote Post Goto Top
 
DJ-Habana
C# King
[ *  *  *  *  *  * ]
Thanx Dr.Best I think it worked just had to change a few data but I did this in my camera step event.
Code:
 

if active = true {
GetMousePos();
rotatex+=(global.mouse_y-display_get_height()/2)*mouse_speed;
if(rotatex<-45){
rotatex=-45;}
if(rotatex>45){
rotatex=45;
}
follow.shoot_rotx=rotatex;
follow.roty+=((global.mouse_x-display_get_width()/2)*mouse_speed);
temproty+=((global.mouse_x-display_get_width()/2)*mouse_speed);
SetMousePos(display_get_width()/2,display_get_height()/2);
MoveCamera();
}

Dist=CheckRayIntersection(all,x,y,z,rotatex,temproty,0);
InputVect=CreateDirectionVector(-1,rotatex,temproty);
if (Dist<90000)
{
CalculateVectorScalarProduct(InputVect,InputVect,Dist);
global.X=GetVector(InputVect,1)+x;
global.Y=GetVector(InputVect,2)+y;
global.Z=GetVector(InputVect,3)+z;
}

ReleaseVector(InputVect);

bulroty = point_direction(x,y,global.X,global.Y)+90
follow.bulroty = bulroty


No just gotta add the bulrotx :

EDIT : I tried the following for rotx

bulrotx = point_direction(x,y,point_distance(x,y,global.X,global.Y),global.Z);

bulrotx = point_direction(0,0,point_distance(0,0,global.X,global.Y),global.Z);

But neither of them workes
Edited by DJ-Habana, Nov 23 2010, 08:04 PM.
Posted Image


Offline Profile Quote Post Goto Top
 
DJ-Habana
C# King
[ *  *  *  *  *  * ]
This is bassicly I am trying to acomplish:

Posted Image

The red line is bassicly the direction I want for the bullet to go
Attached to this post:
Attachments: Untitled.jpg (18.77 KB)
Edited by DJ-Habana, Nov 23 2010, 08:18 PM.
Posted Image


Offline Profile Quote Post Goto Top
 
DJ-Habana
C# King
[ *  *  *  *  *  * ]
OK I tried something else:
bulrotx = arctan((global.Z-z)/distance_to_point(global.X,global.Y))

But got this error:
___________________________________________
ERROR in
action number 1
of Step Event
for object camera:

Error in code at line 27:
bulrotx = arctan((global.Z-z)/distance_to_point(global.X,global.Y))
^
at position 32: Division by 0.
Posted Image


Offline Profile Quote Post Goto Top
 
DJ-Habana
C# King
[ *  *  *  *  *  * ]
ok now I tried this
bulrotx = arctan((global.Z-z)/distance_to_point(x,y,global.X,global.Y))

It works but it is then exactly the same as the camera roty and rotatx this means that the bullet still goes as described in the picture
like the black lines and I want the bullet to create a direction like the red line
Does Any one have a sullotion or maybe a more acurate AIMing for 3rd person games
I am desperate now lol
Posted Image


Offline Profile Quote Post Goto Top
 
« Previous Topic · Questions about Ultimate 3D · Next Topic »
Add Reply