About Store Forum Documentation Contact
Donations:
227$/mo



Post Reply 
Different results when using Physics.ray with callback and without it
Author Message
Harry Offline
Member

Post: #1
Different results when using Physics.ray with callback and without it
Hi,

I check these two codes:

Code:
PhysHit bd;
if(Physics.ray(start, end-start,&bd)){
    D.dot(RED,PosToScreen(bd.plane.pos));
    D.line(GREEN,posi,bd.plane.pos);
}

BulletDetection bd2;
Physics.ray(start, end-start, bd2);
if(!bd2.sky){ // if hitted any objet
    D.dot(YELLOW,PosToScreen(bd2.phys_hit.plane.pos));
    D.line(BLUE,posi,bd2.phys_hit.plane.pos);
}

where BulletDetection:

Code:
struct BulletDetection :PhysHitCallback
{     
    PhysHit phys_hit;
    Bool sky;
    
    virtual Bool hit(PhysHit &phys_hit);

    BulletDetection(){sky=true;}
};

When hit is called i save phys_hit informations for further use and set sky to false. These two codes give me different result when I aim objects embedded into terrain what ou can see on screenshot: http://i46.tinypic.com/2nlws9c.jpg

Did I understand something wrong or it is bug in engine? I think that using callback for detecting which type of object bullet hits is better solution than using Physics.ray without callback?
01-05-2013 10:38 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Different results when using Physics.ray with callback and without it
callback version reports all contacts, not just first one
01-06-2013 10:48 PM
Find all posts by this user Quote this message in a reply
Harry Offline
Member

Post: #3
RE: Different results when using Physics.ray with callback and without it
So if I understand it when I return false in PhysHitCallback::hit() method checking will stop and ray will report only first contact?

If yes then I still have this problem. Here everything is ok:
http://i50.tinypic.com/e9voyb.jpg
but I'll fly player slightly up and I get this:
http://i50.tinypic.com/2daalbm.jpg
01-07-2013 03:26 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: Different results when using Physics.ray with callback and without it
Quote:only first contact?
first contact in the callback does not need to be the closest one
(they're not sorted in the callback)
01-12-2013 03:47 PM
Find all posts by this user Quote this message in a reply
Harry Offline
Member

Post: #5
RE: Different results when using Physics.ray with callback and without it
So if I want only detect first collision I should use PhysHit instead of callback?
01-13-2013 01:18 PM
Visit this user's website Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #6
RE: Different results when using Physics.ray with callback and without it
Yes, that is correct.
(This post was last modified: 01-14-2013 06:19 AM by fatcoder.)
01-14-2013 06:17 AM
Find all posts by this user Quote this message in a reply
Harry Offline
Member

Post: #7
RE: Different results when using Physics.ray with callback and without it
Thanks for help smile
01-14-2013 07:16 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply