Jump to content

Custom player for hovercraft.


photo

Recommended Posts

Posted

Hi

 

I need to make a custom player for a hovercraft type of vehicle.

I need to implement a special type of control and I need to know the distance to ground level to be able to get the physics right.

 

Can I do that using scripting? Or do I need to subclass the Player class and add new funcionality in C++?

 

Can I use scripting to get the distance from player to for instance ground level or distance to any object in a selected direction?

Posted
Can I use scripting to get the distance from player to for instance ground level or distance to any object in a selected direction?

 

In script you can use this function

 

 

engine.world.getIntersection

Object engine.world.getIntersection(vec3 p0,vec3 p1,int mask,int ret[])

Description

Performs tracing from the p0 point to p1 to find an Object located on that line. This function detects intersection with surfaces (polygons) of mesh objects and terrain object with intersection flag. Intersection is found only for objects with a matching mask.

World space coordinates are used for this function.

Notice

You may want to call updateSpatial() before finding intersections.

Arguments

 

vec3 p0 - Source point.

vec3 p1 - Destination point.

int mask - Intersection mask.

int ret[] - Return array, its components are:

  • ret[0]: intersection point (vec3), in the world coordinates.
  • ret[1]: normal of the intersection point (vec3).
  • ret[2]: texture coordinates of the intersection point (vec4; vec4.xy is for UV channel 0, vec4.zw is for UV channel 1).
  • ret[3]: surface number.

Return value

 

 

Reference to the first crossed object or NULL (0) if no object is crossed.

 

player or hover craft position is the source point and the hovercrafts down direction (multiplied to how far you want to test the ground against) will be the destination point. Effectively this does a ray cast with the floor. Use a unique bit mask for your terrain and/or any other objects you want to find an intersection point with. Then distance is just the length between the source and intersection point.

 

 

As for choice in player object I can't be sure exactly how you want to control it but I recommend looking at PlayerPersecutor and attaching it to your hovercraft. By fixing it you can manually change distance, phi/theta angles with each update based on your hovercrafts current transform. PlayerPersecutor::setViewDirection would also make things easy in that respect. Hope that helps

×
×
  • Create New...