[SOLVED] Raycasting from sides of a entity

I was trying to make a wallride so I was going to use a ray cast to check if you are on the left or right side of the wall. But I cant figure out how to fire to the sides.

Hi @EXECUTABLE and welcome! The most easy way is to create a child entity that has the correct end position for the raycast. Then you can use the position of this child entity as end position for the raycast.

1 Like

how would I contact the child entity for example, if I were trying to talk to the entity the script is on it would be this.entity, what would I put to talk to the child entity?

There are several ways to do this.

For example, you can create an attribute and add the child entity to it.

You can also search for the child entity by name, like the two examples below.

var leftEntity = this.entity.findByName('LeftChild');
var leftPosition = leftEntity.getPosition();
var leftPosition = this.entity.findByName('LeftChild').getPosition();

It is returning: Uncaught TypeError: Cannot read properties of undefined (reading ‘findByName’)

here’s the link to my project: PlayCanvas 3D HTML5 Game Engine

I’m sorry

You are trying to create a global variable (on an incorrect way), which is not necessary in your case. I suggest to use my second example and do it in the actual function.

it still returns: Uncaught TypeError: Cannot read properties of undefined (reading ‘findByName’)

Im very sorry if I’m being dumb

Please check what is the function, because right now it’s before the function.

oh my god i am so sorry thank you

1 Like