I have a raycast problem

why doesnt this work, i parented it to the camera

var Raycast = pc.createScript(‘raycast’);

Raycast.attributes.add(‘color’, {type : ‘rgba’});
// initialize code called once per entity
Raycast.prototype.initialize = function() {
this.app.mouse.on(pc.EVENT_MOUSEDOWN, this.mouseDown, this);
};

// update code called every frame
Raycast.prototype.update = function(dt) {

};

Raycast.prototype.mouseDown = function(e){
this.doRaycast(e.x, e.y);
};

Raycast.prototype.doRaycast = function (screenX, screenY) {
var from = this.entity.getPosition();
var to = this.entity.camera.screenToWorld(screenX, screenY, this.entity.camera.farClip);
var result = this.app.systems.rigidbody.raycastFirst(from, to);
if (result) {
this.app.renderLine(from,to,this.color);
}
};

Hello @jus.co_ding_me_23! It does not answer your question, but if you want to post some of your code, please do it correctly so that your code is easier to read.

ok, so like this

var Raycast = pc.createScript(‘raycast’);

Raycast.attributes.add(‘color’, {type : ‘rgba’});
// initialize code called once per entity
Raycast.prototype.initialize = function() {
this.app.mouse.on(pc.EVENT_MOUSEDOWN, this.mouseDown, this);
};

// update code called every frame
Raycast.prototype.update = function(dt) {

};

Raycast.prototype.mouseDown = function(e){
this.doRaycast(e.x, e.y);
};

Raycast.prototype.doRaycast = function (screenX, screenY) {
var from = this.entity.getPosition();
var to = this.entity.camera.screenToWorld(screenX, screenY, this.entity.camera.farClip);
var result = this.app.systems.rigidbody.raycastFirst(from, to);
if (result) {
this.app.renderLine(from,to,this.color);
}
};

1 Like

Hi @jus.co_ding_me_23,

By not working you mean the line isn’t rendered? Two things come to mind:

  • Make sure you click and hold, render line works per frame that means you should be calling it during a span of frames to see it on screen
  • Debug print on the browser console the two positions, from and to, to make sure they are valid numbers.

it still doesnt work

You won’t be able to see the line as it’s always going from the camera position outwards. It’s like looking down a pixel wide needle all the time.

1 Like

how do i see it

What are you trying to do with this line? What is it for?

i am trying to make a line to signify the grapple line for a grappling hook

Render line is meant to be for debugging only. I would use something else to represent the rope such as a model (like a cylinder) that you can scale or generate a mesh.

Render line will also only render the frame that the function is called. If you want to see it all the time, you need to call the function every frame.

ok

i have left that game I was making @yaustar . Playcanvas is a good engine, but it can’t be used fir some specific stuff. The setTimeout also has a tiny bug.

You made me curious. Could you elaborate on this thought?

i mean, i have used unity, and i can do stuff way more. Here some themed games like shooters or something, this is ‘good’, or ‘manageable’ but when it comes to full fletched games or stories or stuff, playcanvas is stilll in the ameature zone, saying that,those type of games are IMPOSSIBLE.

Unity does offer a lot of stuff out of the box that we don’t have. At the same time, the size of download in the browser compared to Unity is much smaller.

It’s part of the reason why developers of games like venge.io choose to use PlayCanvas over Unity.

All that said, choose the right tool for you. There’s no point using something if it’s not making you productive.

i like playcanvas though. I tried unity. It was good, but i couldnt publish it well. One advantage of playcanvas, even with some tiny bugs and errors in my code,playcanvas is simple to use. That’s why Im using it. (It might even be better than babylon). but please add more 2d stuff. I am a 2d guy. i used to use unity and construct 3, but this is simple and works well on browser, one question, how do you make playcanvas games available on the play store, i saw something like that in the tutorials.

You have to wrap the HTML5 page into a native app. This page gets you most of the way, the bit that missing is all the signing and the Android build process which is covered on the Cordova site. https://developer.playcanvas.com/en/user-manual/publishing/mobile/cordova/

ok, thanks