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 / How do I do ObjectRaycast the right way?

Author
Message
Xaby
FPSC Reloaded TGC Backer
17
Years of Service
User Offline
Joined: 17th Apr 2007
Location: Berlin
Posted: 2nd Mar 2017 18:03 Edited at: 2nd Mar 2017 18:54
Hello everyone.

I wanted to try something like minecraft. I wanted to look at a cube and raycast the cube with ObjectRayCast(0...) from my Head (camera on an object) to faraway.
This works all good. I knew with


If GetObjectRayCastNumHits()>0
HitID = GetObjectRayCastNumHits()-1
hitObjID = GetObjectRayCastHitID(HitID)
EndIf

I will get the right object I am looking at. But I want to draw a transparent cube where the new one can be placed. And there is the problem. I don't want to cast the Object I want to place or other helper-objects and Brush-Visuals for the Objects I want to place or 3D Arrows to show where I can do something.

How can I cast all, but only special objects not or how can I cast groups of objects? Or is there an easy way arround?

Something with the HitID, but I can't figure out, how I cast through the object that is nearest to me, but not the object I want to cast, because that's the object I want to place.

Thanks for help.

I changed the tutorial to ObjectRaycast and GetObjectRayCastX, but in the last example there is only one Object.
I don't know how to do this red ball the easy way.

[youtube]https://www.youtube.com/watch?v=sM4T_sZO6KI[/youtube]

My Code so far
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 2nd Mar 2017 18:15
there are commands to convert screen pos. into 3d direction.
AGK (Steam) V2017.01.09 : Windows 10 Pro 64 Bit : AMD (16.12.1) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
Xaby
FPSC Reloaded TGC Backer
17
Years of Service
User Offline
Joined: 17th Apr 2007
Location: Berlin
Posted: 2nd Mar 2017 18:58
@Markus

sounds great, but how can I use this information with the problem, that I want to cast not every object in the ray? My program hast to work also in 3rd person and other camera angles.

Can you post a little code snippet, do clarify your thought?

Thanks for help.
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 2nd Mar 2017 22:48
There are a couple of ways to do this. Below is an example of what I think is simplest.



In this example I've used a flag that simply gives a state for the box which controls whether the collision for the box is turn on or off. In your case you will want to control the box's state depending of whether the box has been positioned or not. You might actually want more than two states. You might want:

state = 0 -- box has not been placed and is invisible and there should be no interaction with this box.
state = 1 -- box is being placed, is transparent but doesn't block line of sight
state = 2 -- box has been placed and now blocks line of sight.

If you want to do groups then you could have a group variable in the _box_type - or whatever other objects you might have - and then when you want to do collision with a particular group simply turn off the collision for all the other groups. Another way to do groups is to only loop through the objects that you are interested in and check collision with each individual object in that group but this won't necessarily give you the id of the nearest object.

I also did an object picker which you also might find useful: https://www.appgamekit.com/documentation/Reference/3D/Get3DVectorXFromScreen.htm
Hover Car Race Challenge! - available now on Google Play
Invaders of the 29th Dimension - available now on Google Play
Find me on indieDB
Xaby
FPSC Reloaded TGC Backer
17
Years of Service
User Offline
Joined: 17th Apr 2007
Location: Berlin
Posted: 3rd Mar 2017 07:56 Edited at: 3rd Mar 2017 08:08
@Markus, @29 Games,

thanks for your fast answer.

@29 games, your example is great, maybe this could be added to the examples too

That was my missing command
SetObjectCollisionMode( objID, mode )
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 3rd Mar 2017 09:12
the commands in meant was
Get3DVectorXFromScreen ( x, y )
Get3DVectorYFromScreen ( x, y )
Get3DVectorZFromScreen ( x, y )
GetScreenXFrom3D ( x, y, z )
GetScreenYFrom3D ( x, y, z )

RayCast give you a list, you can also igrone obj ids from the result.
AGK (Steam) V2017.01.09 : Windows 10 Pro 64 Bit : AMD (16.12.1) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
Xaby
FPSC Reloaded TGC Backer
17
Years of Service
User Offline
Joined: 17th Apr 2007
Location: Berlin
Posted: 5th Mar 2017 07:34
@Markus, I understand, that you meat these commands, but to use them, I have to know, where the Ray hits the object. The example from 29 Games is realy that, what helped me out.

Login to post a reply

Server time is: 2024-05-19 01:27:43
Your offset time is: 2024-05-19 01:27:43