I see there are 2 applications of raycast: entity picking and determine if an entity is on the ground:
Ray casting has other applications too. An entity can probe the environment by firing ray casts. For example, to determine if an entity is on the ground, it can fire a ray cast directly downwards some distance and check if it intersects with the environment.
With entity picking I see there is example.
So Where I can find example of second application of raycast it is determine if an entity is on the ground?
Not sure if there is an example, but it isn’t much different. You just need to cast a ray from a position pointing to the ground.
Something like this:
// this will cast a ray 100 units from the current entity pos pointing down
var from = this.entity.getPosition();
var to = new pc.Vec3().copy(from);
to.y -= 100;
var result = this.app.systems.rigidbody.raycastFirst(from, to);
Yes I have the ray
const ray = new pc.Ray(this.carEntity.getPosition());
A ray requires a position and a direction:
So if you are using a ray in your code, point it to the ground like this:
const ray = new pc.Ray(this.carEntity.getPosition(), pc.Vec3.DOWN);
ok I get it
because I read the ray is infinite but it can be set with some distance