How can you do Ray Casting in Minetest?

Post Reply
User avatar
Me Me and Me
Member
Posts: 56
Joined: Sun Jul 03, 2016 21:08
In-game: MeMeandMe2 Regulus
Location: Vulcan, in the leftmost star of Orion's Belt

How can you do Ray Casting in Minetest?

by Me Me and Me » Post

Hi! I'm trying to make a beam-like gun in minetest,
and I know in some game engines you use "Ray Casting" to emit the beam.
So I was wondering, is there an easy way to do that in minetest?

Thanks, Me Me and Me.
I Love Formspecs!

User avatar
rubenwardy
Moderator
Posts: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: How can you do Ray Casting in Minetest?

by rubenwardy » Post

If you search for raycast lua_api, you'll see there's a function called minetest.raycast
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
stu
Member
Posts: 923
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11
Location: United Kingdom

Re: How can you do Ray Casting in Minetest?

by stu » Post

Me Me and Me wrote:Hi! I'm trying to make a beam-like gun in minetest,
and I know in some game engines you use "Ray Casting" to emit the beam.
Do you mean like a laser-beam? If so then that is not really what ray-casting means in game-engine terms. `minetest.raycast` is generally used to detect objects or nodes that intersect an imaginary line (or ray) which may be useful to tell if your gun has actually 'hit' anything but will not emit any kind of beam.

AFAIK it should be possible to project some sort of beam using particle effects.

User avatar
Me Me and Me
Member
Posts: 56
Joined: Sun Jul 03, 2016 21:08
In-game: MeMeandMe2 Regulus
Location: Vulcan, in the leftmost star of Orion's Belt

Re: How can you do Ray Casting in Minetest?

by Me Me and Me » Post

stu wrote: Do you mean like a laser-beam? If so then that is not really what ray-casting means in game-engine terms. `minetest.raycast` is generally used to detect objects or nodes that intersect an imaginary line (or ray) which may be useful to tell if your gun has actually 'hit' anything but will not emit any kind of beam.

AFAIK it should be possible to project some sort of beam using particle effects.
Thanks stu, I'll use particles for the beam in my gun mod.
I Love Formspecs!

sofar
Developer
Posts: 2146
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: How can you do Ray Casting in Minetest?

by sofar » Post

Me Me and Me wrote:Thanks stu, I'll use particles for the beam in my gun mod.
particles may not work as there's no `yaw` and `pitch` value for particles, so you can't make a `line` that follows an arbitrary 3d vector. You'll have to get really smart with mesh entities to do it, or use a bajillion particles.

twoelk
Member
Posts: 1482
Joined: Fri Apr 19, 2013 16:19
GitHub: twoelk
IRC: twoelk
In-game: twoelk
Location: northern Germany

Re: How can you do Ray Casting in Minetest?

by twoelk » Post

no beacons possible that may guide me home from far away? - sigh, no working pharus of Alexandria then

sofar
Developer
Posts: 2146
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: How can you do Ray Casting in Minetest?

by sofar » Post

twoelk wrote:no beacons possible that may guide me home from far away? - sigh, no working pharus of Alexandria then
Beacons are vertical, so you can use particles. But a beam that isn't vertical isn't easy to make with a particle.

User avatar
sorcerykid
Member
Posts: 1847
Joined: Fri Aug 26, 2016 15:36
GitHub: sorcerykid
In-game: Nemo
Location: Illinois, USA

Re: How can you do Ray Casting in Minetest?

by sorcerykid » Post

It would be great if there was a way to do light beams in Minetest, but the engine doesn't support it. Even using an entity, the beam itself won't be luminescent because only nodes can serve as light sources. There is no dynamic lighting in Minetest, only-stationary.

User avatar
stu
Member
Posts: 923
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11
Location: United Kingdom

Re: How can you do Ray Casting in Minetest?

by stu » Post

sofar wrote:particles may not work as there's no `yaw` and `pitch` value for particles, so you can't make a `line` that follows an arbitrary 3d vector. You'll have to get really smart with mesh entities to do it, or use a bajillion particles.
Oh, I was not aware of this limitation. I have not done much with particles and was actually thinking about how you used them for lightning, of course that is rather different to a linear directional beam.

I still wonder if you did project enough particles continuously with the right velocity that it could appear like a straight beam due to persistence of vision. You'd have to try it I guess. And yes, doing this with entities would be very cumbersome and probably would not work too well in multiplayer.
sorcerykid wrote:It would be great if there was a way to do light beams in Minetest, but the engine doesn't support it. Even using an entity, the beam itself won't be luminescent because only nodes can serve as light sources. There is no dynamic lighting in Minetest, only-stationary.
I would also like a way to draw 3d lines in the world space that might be managed in a similar way to particles, however, I think the best we could hope for is 'glow' for the time being. I think that dynamic lighting will not be making it into MT 0.5.0 =)

sofar
Developer
Posts: 2146
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: How can you do Ray Casting in Minetest?

by sofar » Post

sorcerykid wrote:It would be great if there was a way to do light beams in Minetest, but the engine doesn't support it. Even using an entity, the beam itself won't be luminescent because only nodes can serve as light sources. There is no dynamic lighting in Minetest, only-stationary.
Particles can't emit light, but they can appear to be `lit` to max light values, which is what the lightning mod uses to make the lightning bolt appear brightly in the sky. This can be used to create effects that at least have some illusion of creating light.

I then add a `fire` node at the impact site that actually does emit light. Good enough for lightning, and the method may be usable by other mods to do similar things.

sofar
Developer
Posts: 2146
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: How can you do Ray Casting in Minetest?

by sofar » Post

stu wrote: I still wonder if you did project enough particles continuously with the right velocity that it could appear like a straight beam due to persistence of vision. You'd have to try it I guess. And yes, doing this with entities would be very cumbersome and probably would not work too well in multiplayer.
Trivial with a particle generator and some simple math that calculates the proper 3d vector and puts it in velocity, and calculate the speed value such that the particles disappear right at the target. However, the amount of particles needed to get a good visual may be problematic, and cause the client to drop FPS.

User avatar
stu
Member
Posts: 923
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11
Location: United Kingdom

Re: How can you do Ray Casting in Minetest?

by stu » Post

sofar wrote:Trivial with a particle generator and some simple math that calculates the proper 3d vector and puts it in velocity, and calculate the speed value such that the particles disappear right at the target. However, the amount of particles needed to get a good visual may be problematic, and cause the client to drop FPS.
Yeah, that's kinda what I was thinking about. In theory though, particles should be really inexpense in terms of client FPS, sadly I realise that this is not quite the case for MTE right now.

twoelk
Member
Posts: 1482
Joined: Fri Apr 19, 2013 16:19
GitHub: twoelk
IRC: twoelk
In-game: twoelk
Location: northern Germany

Re: How can you do Ray Casting in Minetest?

by twoelk » Post

didn't irrlicht have something like spotlight?

Astrobe
Member
Posts: 577
Joined: Sun Apr 01, 2018 10:46

Re: How can you do Ray Casting in Minetest?

by Astrobe » Post

Sorry a bit OT, but what would be your advice for having fireworks arrows light briefly the neighborhood? I'd like to use them in mines (I believe they may be better balance-wise than torch arrows). Maybe create a temporary glowing node? Can I create for instance a glowing air node or something like that?
My game? It's Minefall.

sofar
Developer
Posts: 2146
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: How can you do Ray Casting in Minetest?

by sofar » Post

stu wrote: Yeah, that's kinda what I was thinking about. In theory though, particles should be really inexpense in terms of client FPS, sadly I realise that this is not quite the case for MTE right now.
with this merge: https://github.com/minetest/minetest/pull/6072

it should be possible, likely, to do this entirely client side, which would significantly increase the amount of particles you could generate if you needed more than 1 particle spawner. And you'd get zero-latency visuals.

I tested an early CSM particle PR and easily could do 2k particles per second I think.

User avatar
rubenwardy
Moderator
Posts: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: How can you do Ray Casting in Minetest?

by rubenwardy » Post

sofar wrote:with this merge: https://github.com/minetest/minetest/pull/6072

it should be possible, likely, to do this entirely client side, which would significantly increase the amount of particles you could generate if you needed more than 1 particle spawner. And you'd get zero-latency visuals.

I tested an early CSM particle PR and easily could do 2k particles per second I think.
That helps when you need to modify spawner positions a lot, but that is not the reason particles are slow in most cases. The reason is we use a scene node *per particle*. This causes a large amount of calls to the GPU
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
stu
Member
Posts: 923
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11
Location: United Kingdom

Re: How can you do Ray Casting in Minetest?

by stu » Post

rubenwardy wrote:The reason is we use a scene node *per particle*. This causes a large amount of calls to the GPU
Well yeah, that ought to do it :D Although it does beg the question, why we don't use Irrlicht's built-in support for particle systems, IParticleSystemSceneNode & friends?

User avatar
rubenwardy
Moderator
Posts: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: How can you do Ray Casting in Minetest?

by rubenwardy » Post

Because the pr was sloppily made and should never have been merged
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

Post Reply

Who is online

Users browsing this forum: j0j0n4th4n and 3 guests