Author Topic: Raycasting  (Read 4740 times)

I want a weapon to use raycasting instead of projectiles.

I took a look into some of the weapons that use it and it seems simple enough.

Except, I want an emitter drawn along the vector, and I want it to redirect towards a player if it travels within X units of them. It currently does this using projectiles, but I want this to travel faster than I'm allowed to set the projectile speed, so the only other option is raycasting.



So if I were to shoot this now...




it would arc towards the feet of the bot instantly, and pain would ensue.

Is this possible without a stuffload of low-level coding (ie writing my own modified raycasting function)? If not, is there ANY way to disable the projectile speed cap? I know this is kind of a no-no for ghosting but the extra delay between the shot and the explosion is really bugging me.

this is definitly possible, all you do is check if the projectile is in range of a player, then make it face the player. I would post some code but unrortunatly i code like stuff on touchscreens. Ill get to it tommorow if no one does it.

this is definitly possible, all you do is check if the projectile is in range of a player, then make it face the player. I would post some code but unrortunatly i code like stuff on touchscreens. Ill get to it tommorow if no one does it.
Interesting, and relieving. I know nothing of raycasting and very little of torque in general, so I was pretty much lost.

Thanks.

The homing rocket add-on has something like this, once the weapon shoots the projectile, it decides to find the closest person/bot.

The homing rocket add-on has something like this, once the weapon shoots the projectile, it decides to find the closest person/bot.
I have the homing part down, my issue is doing it using raycasts

the Homing RL uses projectiles as well as an extremely complex/impressive algorithm that slowly curves the projectile towards the player instead of instantly redirecting it; much different from what I'm trying to achieve

« Last Edit: April 28, 2014, 11:22:10 PM by takato14 »

this is definitly possible, all you do is check if the projectile is in range of a player, then make it face the player. I would post some code but unrortunatly i code like stuff on touchscreens. Ill get to it tommorow if no one does it.
I don't think that's what he wants. You're still talking projectiles here.

We're actually faced with an interesting problem here. Since raycasts don't return until they hit an object, I'm fairly sure that, without some intense programming madness, that you will not be able to detect a player as a raycast passes by them, and then redirect. As a ray, it continues forever until it hits an object.

HOWEVER, don't worry just yet. As I was typing the above paragraph, I thought of an alternative. Here's how it would go down. First, once you've sent the fire signal, initialize and return a container search for player typemask within the weapon's range. Then, find the dot product between the crosshairs/head/muzzlePoint of the gunner and the players found in the container search. Pick out the player with the smallest angle, and set that object id as your target. Then, begin the raycast for the actual "projectile", directly ahead. Get the current distance and angle of the player and target, and calculate the angle of "refraction" (it's not really refraction, I know) using trig functions. Fire the emitters along these two vectors, and they should meet up. Of course, cancel if any the raycasts encounter another typemask (save water) first. This means you'll need to schedule your raycasting.

I hope this helps!

What if a brick is between you and the player but the player could be hit with an arc shot. Should that be possible?

What if a brick is between you and the player but the player could be hit with an arc shot. Should that be possible?
Yes, I guess that would make sense. In that case, he'd want to only check for non-player typemasks on the actual arc raycasts, and not on the player locating one.

There would be only 2 raycasts, one in the direction the laser fires and one from the point where it intersects the radius to the player to the target.

dear god this is every bit as daunting as I feared it would be

I don't know torquescript well enough to do this yet, I'm gonna need to do some math exercises and look up a lot of resources to pull this off

thanks for your help, I'll probably need help with the code itself so expect a lot of posts

What if a brick is between you and the player but the player could be hit with an arc shot. Should that be possible?
No, it doesn't do that in the game I'm basing this weapon off of so it shouldn't do it here

There would be only 2 raycasts, one in the direction the laser fires and one from the point where it intersects the radius to the player to the target.
Then how would you detect players in-range? The laser raycast can't just know when a player is nearby. A third is needed for triangulation.

Then how would you detect players in-range? The laser raycast can't just know when a player is nearby. A third is needed for triangulation.
You can't find nearby players with raycasts at all.

Use math instead.

You know the start position of the laser.
You know the direction it goes.
You know the position of all players in the server.
You know the range the players should have to the laser.

http://en.wikipedia.org/wiki/Line%E2%80%93sphere_intersection

The line is the laser, the sphere is the radius around the players.

You check for all players that are within the max range of the laser to your player. If you get 0 intersections, ignore. If you get 1 intersection, use that. If you get 2, use the one closer to yourself.

Then compare all the points you got and kill the player thats closest to you.

So are you implying that a container search gives you distance as well? I don't remember, so that's why I threw the third raycast in there.

Who said anything about container searches or raycasts?

Well, while everyone is working out how to do the raycasting stuff, is it even possible to create emitters along a curved line faster than a projectile?

I guess you could make emitter nodes along the line that all fire an emitter in the direction of the curve at that point.

I know there's some vars that you can modify with particles and emitters that will let you make a curved projection, but you cant be modifying datablocks at runtime..


Edit: Hmm. Actually, i think you could sorta do it with the emitter datablock variables. You would have to place an emitter node at the muzzle point, then rotate it so that the 'beam' of particles arc in the direction you want. Although then you would need a way to adjust how wide the arc is, and where it stops, which you would need to modify the datablock again..
This is tough.
« Last Edit: April 30, 2014, 10:31:34 AM by boodals 2 »