Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / T2: Raycast Multiple Objects Hit

Author
Message
Greg_C
14
Years of Service
User Offline
Joined: 22nd May 2010
Location:
Posted: 1st Mar 2012 02:14 Edited at: 1st Mar 2012 03:22
So when I do a drag event I create a RayCast from the point the drag started to when it ended. My issue is how to take what was hit and relay that to my Object Class to run specific functions on that class. I know something was hit and where it was hit but I need to be able to set off a flag in my object class that it has been hit.

Also if I do this raycast and there are multiple objects in the raycast will it still only return the first one hit?

EDIT:
Got the first part to work still wondering about the second question and I have a new question.

How could I send an impulse in the direction that the ray cast was going?
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st Mar 2012 10:33
Quote: "How could I send an impulse in the direction that the ray cast was going?"

You already have the start and end point of your ray. To turn that into a pair of "unit vectors" you need to get the distance between the two points and divide the difference in X and Y by that value and then use the unit vextors (between -1.0 and 1.0) to multiply by your impulse strength...

In code:

...written from my head so you might want to test it.

Greg_C
14
Years of Service
User Offline
Joined: 22nd May 2010
Location:
Posted: 1st Mar 2012 22:13
Tested it and works great! Math isn't something I am really to great at Do you think you could explain the idea behind this? Why you thought of this basically. I don't like using code that I can't fully understand as I don't learn anything from it.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st Mar 2012 23:49
OK sure.

When you want to move towards a X,Y co-ordinate from another X, Y co-ordinate at a certain speed you need to work out how much of that speed to give to X and how much to give to Y.

A unit vector gives you a factor (a percentage of 1.0) to apply to your speed in X and Y without having to start thinking about trigonometry too much.

You know how far in X and Y you are from your target and using Pythagoras you can work out the total distance. A Unit Vector is simply the distance in X or Y in relation to the total distance.

I hope that makes sense because I'm a little tired and have had a few ales

Greg_C
14
Years of Service
User Offline
Joined: 22nd May 2010
Location:
Posted: 2nd Mar 2012 03:26 Edited at: 2nd Mar 2012 03:26
That helps a lot more than just using the code. Now I can put this towards other problems in the future

Thanks!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 2nd Mar 2012 09:16
Re-reading it sober and awake I didn't do a bad job

Glad to help

Login to post a reply

Server time is: 2024-11-23 04:49:19
Your offset time is: 2024-11-23 04:49:19