Adam's Lair Forum

game development and casual madness
It is currently 2019/09/17, 15:17

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Raycasting
PostPosted: 2014/01/25, 21:16 
Member
Member
User avatar

Joined: 2014/01/25, 21:14
Posts: 52
Role: Hobbyist
I can't find where I can do a raycast.
Where would I do this and how do I find stuff like this myself?
Thanks!


Top
 Profile  
 
 Post subject: Re: Raycasting
PostPosted: 2014/01/25, 21:32 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 2073
Location: Germany
Role: Professional
Try RigidBody.Raycast.

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
 Post subject: Re: Raycasting
PostPosted: 2014/01/26, 00:01 
Member
Member
User avatar

Joined: 2014/01/25, 21:14
Posts: 52
Role: Hobbyist
Adam wrote:
Try RigidBody.Raycast.

Ah, gotcha.
I don't understand the third argument though. I've used Farseer with XNA before, but this works a lot differently.


Top
 Profile  
 
 Post subject: Re: Raycasting
PostPosted: 2014/01/26, 00:21 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 2073
Location: Germany
Role: Professional
As far as I know, Farseer too has a RaycastCallback - its purpose is the same as for the one in Duality. :) They both allow you to take action on how to handle shapes that are detected to be intersecting the ray that is casted. You might want to ignore certain shapes, instead of clipping the ray on collision, or you might want to adjust the way in which clipping is performed. That's what the callback is for. See here for more information.

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
 Post subject: Re: Raycasting
PostPosted: 2014/01/26, 00:35 
Member
Member
User avatar

Joined: 2014/01/25, 21:14
Posts: 52
Role: Hobbyist
I've used Raycasting in Farseer quite a bit, this is how it works there:

Code:
world.RayCast((Fixture fixture, Vector2 point, Vector2 normal, Single fraction) => {
                return single;
}, startLocation, endLocation);


This is how it works in Duality:
Code:
RigidBody.RayCast(startLocation, endLocation, RaycastCallback)

RaycastCallback is supposed to be a reference to a method as far as I can see. I can't figure out what it should look like exactly...


Top
 Profile  
 
 Post subject: Re: Raycasting
PostPosted: 2014/01/26, 00:39 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 2073
Location: Germany
Role: Professional
Actually, what you have done in Farseer is nothing else than defining an anonymous method, for which you pass a reference to the function. Duality is no different - it just uses a different method syntax for the callback and happens to have a different order of arguments in the Raycast function :)

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
 Post subject: Re: Raycasting
PostPosted: 2014/01/26, 00:50 
Member
Member
User avatar

Joined: 2014/01/25, 21:14
Posts: 52
Role: Hobbyist
Pfff, sorry to bother you all the time, but I seriously can't get it working.

Code:
void ICmpUpdatable.OnUpdate() {

            MouseInput mouse = DualityApp.Mouse;
            if (GameSystem.playerIsAiming && mouse.ButtonHit(MouseButton.Left)) { // Player shoot

                RigidBody body = this.GameObj.RigidBody;

                RigidBody.RayCast(Vector2.Zero, GameObj.Transform.Pos.Xy, RayCastData());

            }
        }

        private RayCastCallback RayCastData() {

            throw new NotImplementedException();

        }


That's what I have now. I do not know what to return because when I want to create a RayCastCallback, it requires another method, making it an endless loop.


Top
 Profile  
 
 Post subject: Re: Raycasting
PostPosted: 2014/01/26, 01:05 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 2073
Location: Germany
Role: Professional
Try something more like this :)

Code:
List<RayCastData> allTheHits = RigidBody.RayCast(
   Vector2.Zero,
   GameObj.Transform.Pos.Xy,
   data => { return data.Fraction; });


Result allTheHits will contain information about all shapes that have been hit, sorted by their distance to the ray origin.

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
 Post subject: Re: Raycasting
PostPosted: 2014/01/26, 01:12 
Member
Member
User avatar

Joined: 2014/01/25, 21:14
Posts: 52
Role: Hobbyist
Adam wrote:
Try something more like this :)

Code:
List<RayCastData> allTheHits = RigidBody.RayCast(
   Vector2.Zero,
   GameObj.Transform.Pos.Xy,
   data => { return data.Fraction; });


Result allTheHits will contain information about all shapes that have been hit, sorted by their distance to the ray origin.


Right! Thanks man!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group