bend a raycast

is there a way to bend a raycast, to match say a parabola?

Only if you “split” the raycast into small pieces. You would need more raycast calls, but with shorter rays.

yeah, thats what i thought, and that sounds a little processor intensive, especially for the mobile platforms

The only thing you could do, is to try different lengths for the rays. I don’t know how you plan to use it, but depending on that, you may try different ray lengths and compare how expensive each of those tests is. But I would also tend to say - even without having any mobile experience - it is probably too expensive.

well, its for a grenade aiming system using the quadratic formula, and all im trying to do is put a big blue dot (or it can be a light) where the grenade will land

Depending on how the environment looks, different tactics may be useful. I personally would make a few raycasts. Depending on where a hit is detected, split that ray again to go closer to the actual hit position and maybe again… That may produce the problem that you miss certain objects with the raycast, so a spherical raycast would be better, but also more expensive.
I expect you are already aware of that. At the end it very much depends on the environment and how precise that big blue dot should be.

um why all this fear about mobile cpu performance? physx on mobile is very fast with raycasts. I would just get a curve line going then slot in raycast in place of the line drawing code and try it.

You will probably find nothing slows down.

If it slows down and IF it was benchmarked as being the cause then you have several options: reducing resolution of curves, yielding after n millisecs of time to spread across frames, setting up physics so it doesn’t raycast every object in the game etc etc…

All this pre-emptive optimisation is worthless.

4 Likes

hippocoder, as I have NO experience with mobiles, it is better to be sceptic than optimistic. But you are right. JM Studios needs to test it and then decide what to do.

Is it just for aiming? Couldn’t your raycast ignore certain layers so that you can place your blue dot?

Bryan

You usually will slow down from graphics long before cpu becomes an issue (its the same for desktops, and practically been the case since forever with desktop cpu’s - unless you are doing something like a simulation).

Nearly always the gpu will be the bottleneck, so it is better to just make it and optimize afterwards as especially with mobiles you can’t really be too sure where the bottleneck is in advance. You can take a good guess, and if I had to guess it wouldn’t be raycasts - unless you’re doing 100 per frame or something :slight_smile:

My current developed app has around 256 lines, 64 balls, rotating worlds and 64 modified sound effects per frame with reverb plus full screen normal mapped graphics at 30fps, so I’m probably thinking that its the graphics which dropped my framerate as it was 60fps before the normal mapping.

actually thats not true.
It heavily depends on the game, but slowing down the graphics prior hitting the cpu is normally only happening with badly done artwort that uses blending etc instead of using proper geometry, in which case the fillrate will hammer you.

Drawcalls for example is a cpu bottleneck, not a gpu one. Same goes for animation, collision, physics

1 Like

hey, im sorry, i was gone for a week, what was this about physx?

Maybe I have mis-understood the problem, but two things come to mind:

A) Why do you need more than 2 ray casts? A parabola is merely a refined curve along two right triangles.

which leads to B…

B) Why a raycast at all? You have point A and you calculate a parabola based on the ? you need an input here, is the power a fixed number? Even if it wasn’t and it was based on some type of metric, like the player holds a button and releases at the right time to get max power…

That whole time you could be adjusting the end point mere based on the starting point + parabolic function == end point of parabola which is a straight vector

Then you just draw the cross hair at the end point.

Sorry if any of that is confusing, but you shouldn’t need to cast multiple rays at all or at the most two, but I think any standard quadradic (ax^2+bx+c) should suffice?

Again, sorry if I have mis-understood.

You can’t raytrace a straight line because you won’t detect when the top of the curve would clip something. (or where the grenade would land if you’re throwing it onto a sloped surface) Its an interesting problem.

I agree with hippocoder - try raycasting in segments first before assuming it will be inefficient.

well, the problem is its uneven terrain, so thats the problem i had with that, i need it to project the light on the place where it will land

Hi, just wondering if you ever found a solution to this ?

No, but I’m thinking of some now

The Solution is to do it in increments. Instead of 1 Raycast, do 10 or 100.

Although depending on the need sometimes you could either avoid it all together, or somewhat fake it.

you can configure a particle sytem to do it

If only you were here over a year ago when they were having the discussion!