|
Post by Karvy on Aug 13, 2016 2:06:06 GMT
Hi again everyone! Still having problems with 3dRad, I can't make it work well even using the correct maths formulas :/ Okay, some days ago I've started this little project as an aiming test. It has a script that is supposed to make the projectile look at a 3d point forward the target (airplane). the projectile must aim this 3d point to make the bullet hit the target so it's basically a prediction system. So I made the maths in 3dRad according to this game developing site where 3dPoint = targetPosition + ( (targetPosition-playerPosition) / (bulletVelocity-targetVelocity) ) * targetVelocity The problem.. bullets never collides with the target.. now I wonder if the problem is the formula or the 3drad physics ... If you want to see my project I've to say I didn't used iObjectVelocity in the equation because for some reason the function didn't returned any value.. it was always 0 (as you can see in the Valueprint). AimingProblem.3dr (292.99 KB) Thanks and Any suggestions would be very apreciated!!!
|
|
|
Post by WhyNot on Aug 13, 2016 4:37:21 GMT
I've just modified the the script a bit I guess It works fine for a turret system is the projectile will be a heat seeker missile. void LocalToParent(int PARENT, int OBJ, Vector3 rotation, Vector3 translation) { Vector3 parentLocation; Quaternion parentOrientation; Quaternion newOrientation; Quaternion objectOrientation; Vector3 forward, location, newLocation; float x,y,z,ud,lr,fb; x = rotation.x; y = rotation.y; z = rotation.z; fb = translation.z; lr = translation.x; ud = translation.y; iObjectLocation(PARENT, parentLocation); iObjectOrientation(PARENT,parentOrientation); iObjectOrientationSet(OBJ,parentOrientation); iVectorRotate(forward,Vector3(lr,ud,fb),parentOrientation); newLocation = parentLocation + forward; iObjectLocationSet(OBJ,newLocation); iQuaternionFromEulerAngles(newOrientation,x,y,z,"xyz"); iQuaternionMultiply(newOrientation,newOrientation,parentOrientation); iObjectOrientationSet(OBJ,newOrientation); } ///---------------------------------------------------------------------------------- void Main() {
float shootTimer; shootTimer++; if(shootTimer >= 25){ //rate of fire iObjectStart(OBJ_0); //start shooting shootTimer = 0; //reset counter }
Vector3 velocity = Vector3(0,0,1);
LocalToParent(OBJ_22,OBJ_22,Vector3(0,0,0),Vector3(0,0,velocity.z)); // the airplane is moving on its Z axis only
Vector3 projectileLoc,targetLoc,futurePos; Quaternion projectileRotation; float distance, time;
iObjectLocation(OBJ_0,projectileLoc); iObjectLocation(OBJ_22,targetLoc); iObjectVelocity(OBJ_22,velocity);
time = (targetLoc.z - projectileLoc.z) / (500 - velocity.z);
futurePos.x = targetLoc.x; futurePos.y = targetLoc.y; futurePos.z = targetLoc.z +80+ time * velocity.z;
iQuaternionLookAt(projectileRotation,futurePos,Vector3(0,1,0)); iObjectOrientationSet(OBJ_0,projectileRotation);
OUT_44 = velocity.z; }
Try it
|
|
|
Post by Karvy on Aug 13, 2016 6:17:01 GMT
Thanks WhyNot it didn't worked as I am expecting but it works a lot better than the last one. BTW why did you added "80"?
|
|
|
Post by WhyNot on Aug 13, 2016 9:51:37 GMT
I added 80 to add 80 to the target location so it will target your plane a bit forward and when your plane reaches there It will collide
B)
|
|
|
Post by TinSoldier on Aug 13, 2016 18:11:58 GMT
i looked at the project too, math isn't my thing. From what i can see, i would guess theres an issue with the math and velocity calculations.. It seems to work generally but is off just a bit. The adjustment YRN made doesn't fix it really, it just makes the shot a little more ahead of the target so it doest intersect at some point, but then does fall behind as before. One possible fix would be to speed up the ammo by twice... This will likely help/fix the issue, but may not be what you want in your project.. Again not being a math guy, does the formula adjust for distance and velocity between target and source, or is it fixed ... i suspect if fixed then the code works, but needs a variable added to allow for speed and distance changes. This my expert advice
|
|
|
Post by Karvy on Aug 13, 2016 19:09:36 GMT
|
|
|
Post by TinSoldier on Aug 14, 2016 0:27:07 GMT
it doesn't adjust for speed and or distance if its using a fixed point to aim.. 3drads builtin process's for targeting do exactly what your script seems to do, it targets the plane, but it should be targeting the planes position before it gets to that position (prediction), to do this it needs to take into account the speed of each vehicle and the distance between them. Does it do this ??, if so or if its suppose to, then there's a math error...
|
|
|
Post by Karvy on Aug 14, 2016 1:28:04 GMT
TinSoldier haa ok, No, the formula isn't fixed, it depends from the target velocity and its distance. anyways, now I know you aren't a "math guy" but do you think there's something wrong with this equation?
|
|
|
Post by TinSoldier on Aug 14, 2016 5:21:02 GMT
i would say yes, as in over all the idea is somewhat flawed. Firstly, how would your script account for the plane turning in mid flight.. it cant adjust the ammo after its shot.. You idea requires the plane / target to move in a straight path at least long enough for a hit. The adjustment that YRN gave you pretty much does that by shooting in front of the targets current position. Another option would be tracking ammo who's path adjust to follow the target till a hit happens or runs out of fuel, that would be easier to create and would increase the hit count too. But if your dealing with bullets... that would be some fancy tracking bullets PS just a thought, but the added "80" mite be applied in the wrong place in the equation, i'm thinking it would be better to add a positive Z offset to the planes location before the math is done, this would allow the math to plan for the planes future position .. I haven't tried to play with it, but a slight script change mite help, if you're not interested in a tracking ammo setup, like a homing missile .
|
|