Is there code to draw a line where the raycast had travelled and stop where it hit?
Hi @Gavin_Durbin,
Yes sure, you can use the following method:
https://developer.playcanvas.com/en/api/pc.Application.html#renderLine
Just make sure to use it in your update method, since it draws a line for a single frame only.
Does it stay there or disappears?
That’s was my point, if you put it in your script update method so it runs on each frame, it will stay there.
If you don’t, it won’t stay there.
Do i just have to copy and paste this into the update when key is pressed?
Well, kind of. You need to pass the start and end positions of your raycast, plus a line color, to the renderLine() method.
How are you using raycasting right now?
I haven’t added it yet, I’m trying to do other stuff first
Yes, i do have it, for my guns
Sorry for taking so long lol
@Leonidas so how would I implement this?
@Albertos do you know how to implement a raycast drawn on the screen?
Yes, if you share your raycast code I can give you the code to make the raycast visible with a line.
Yessir
You can add the code below after line 34 of your script to render a white line.
var color = new pc.Color(1,1,1,1);
this.app.renderLine(from, to, color);
Can i use a variable or attribute for the “to” on the raycast drawing?
You already did that for the raycast itself and I use the same variable for drawing the line.
I have literally no idea on how i would change the raycast direction