[SOLVED] Child object should stay and not move with Parent (Raycast)

Hey Guys

I want to implement a jumping feature to the demo project.
To accomplish that I want to use a raycast, to check whether the player is mid air or grounded.

here the editor link: https://playcanvas.com/editor/project/490668

My Problem:

As I said, I want to check if the player is grounded or not. For this I have a empty child object attached to the parent object. Now I use the raycastFirst() start position of the player and end position of the child object which is underneath the player. This works, however if you spin or go in one direction the child objects starts to roll with the parent and it’s no longer pointing to the floor.
(I draw a line to represent the raycast visually)

TL;DR I want to be able to have the child object point always down.

Or, is it possible for the raycastFirst() method to set a length of the raycast, this would solve my problem and would be more elegent.

If you need more informations, feel free to ask

BR PeanuT

Rather than using another gameobject for the end point of the ray, you can use negative world Y axis. eg

var endPoint = pc.Vec3.DOWN.clone().scale(0.5).add(start);

This makes the end point 0.5 units below the start point in world space.

1 Like

Thank you very much, this is the perfect solution :slight_smile: