| 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: |
| x,y,z for a ray | |
|---|---|
| Tweet Topic Started: Nov 22 2010, 01:04 AM (403 Views) | |
| DJ-Habana | Nov 22 2010, 01:04 AM Post #1 |
|
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; } |
|
| |
![]() |
|
| Dr. Best | Nov 22 2010, 01:10 AM Post #2 |
|
Administrator
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
You can either use CreateDirectionVector(...) among with GetVector(...) or you can use the code from the Move(...) script. |
![]() |
|
| DJ-Habana | Nov 22 2010, 06:29 PM Post #3 |
|
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 |
|
| |
![]() |
|
| Dr. Best | Nov 22 2010, 10:55 PM Post #4 |
|
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. |
![]() |
|
| DJ-Habana | Nov 22 2010, 10:57 PM Post #5 |
|
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.
|
|
| |
![]() |
|
| DJ-Habana | Nov 22 2010, 11:26 PM Post #6 |
|
C# King
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Got This error something about vector id 0 here is my current code:
Edited by DJ-Habana, Nov 22 2010, 11:36 PM.
|
|
| |
![]() |
|
| Dr. Best | Nov 23 2010, 12:18 AM Post #7 |
|
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. |
![]() |
|
| DJ-Habana | Nov 23 2010, 06:41 AM Post #8 |
|
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 |
|
| |
![]() |
|
| Dr. Best | Nov 23 2010, 11:05 AM Post #9 |
|
Administrator
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Correctly it goes like this:
|
![]() |
|
| DJ-Habana | Nov 23 2010, 04:01 PM Post #10 |
|
C# King
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Ok so then I must still do something wrong.
|
|
| |
![]() |
|
| Dr. Best | Nov 23 2010, 04:41 PM Post #11 |
|
Administrator
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Try this:
|
![]() |
|
| DJ-Habana | Nov 23 2010, 07:47 PM Post #12 |
|
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.
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.
|
|
| |
![]() |
|
| DJ-Habana | Nov 23 2010, 08:17 PM Post #13 |
|
C# King
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
This is bassicly I am trying to acomplish:![]() The red line is bassicly the direction I want for the bullet to go Edited by DJ-Habana, Nov 23 2010, 08:18 PM.
|
|
| |
![]() |
|
| DJ-Habana | Nov 24 2010, 08:39 AM Post #14 |
|
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. |
|
| |
![]() |
|
| DJ-Habana | Nov 24 2010, 09:09 AM Post #15 |
|
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 |
|
| |
![]() |
|
| « Previous Topic · Questions about Ultimate 3D · Next Topic » |





![]](http://z1.ifrm.com/static/1/pip_r.png)



Untitled.jpg (37.8 KB)
9:12 PM Jul 11