User mods, screenshots & videos > Watercraft

Mooring or Anchoring Watercraft

(1/2) > >>

Bob425:
Is it possible to implement the car handbrake (space) feature onto a watercraft, so that the watercraft will stay put alongside a wharf or pier, without drifting away?  Or is there any other means of achieving this?

Bob.

andfly:
There is a very elegant and simple method to achieve this purpose.
Using the "velocity" method.

see ---->     http://xtrac.outerraworld.com/wiki/vehicle

Initializing the method with the command:

var vel = this.velocity (true);

you will have three variables available:

vel.linear.x   ->   speed on the axis "x" (lateral displacement)
vel.linear.y   ->   speed on the axis "y" (forward and backward)
vel.linear.z   ->   speed on the axis "z" (top and bottom)

These variables will indicate the speed of movement of the model and will be positive or negative according to the direction of motion.

At this point you can set a "this.extra_force" command with parameters INVERSELY proportional to the acquired quantities and you will get to force the model to remain still in its current position, and completely automatically.

To connect the command to the "handbrake (space)", make sure that the variable "parking" is inserted between the variables of the "update_frame" function, and acts as a coefficient in the "this.extra_force" command.

I hope I was helpful.   :)

Bob425:

--- Quote from: andfly on December 28, 2017, 11:33:21 am ---There is a very elegant and simple method to achieve this purpose.
Using the "velocity" method.

see ---->     http://xtrac.outerraworld.com/wiki/vehicle

Initializing the method with the command:

var vel = this.velocity (true);

you will have three variables available:

vel.linear.x   ->   speed on the axis "x" (lateral displacement)
vel.linear.y   ->   speed on the axis "y" (forward and backward)
vel.linear.z   ->   speed on the axis "z" (top and bottom)

These variables will indicate the speed of movement of the model and will be positive or negative according to the direction of motion.

At this point you can set a "this.extra_force" command with parameters INVERSELY proportional to the acquired quantities and you will get to force the model to remain still in its current position, and completely automatically.

To connect the command to the "handbrake (space)", make sure that the variable "parking" is inserted between the variables of the "update_frame" function, and acts as a coefficient in the "this.extra_force" command.

I hope I was helpful.   :)

--- End quote ---

Very helpful andfly, once again I am in your debt!

Do I assume that this is inserted into the <model Name>.js file.
Can you possibly give me an example of such an insertion?

Bob.

andfly:
In the command Javascript file:

function update_frame (dt, engine, brake, steering, parking) {
// it is important that "parking" is inserted between the return variables
// of the update_frame function

var coeff = 50000;
// coeff determines the intensity of the force
// varies based on boat mass
// (try different values ...)

var vel = this.velocity (true);

this.extra_force ({z: 0, y: 0, z: 0},
{x: -coeff * vel.linear.x * parking, y: -coeff * vel.linear.y * parking});

}


When the "space" button is pressed, the value of variable: parking is "1" and ...
the force comes into action.

Bob425:
I have added the script to my .js file for  the watercraft Smit Rotterdam, but now she floats well above the surface of the water, clearly I am missing something (possibly brains).
The contents of my js file are:-

//vehicle script file
//see http://xtrac.outerra.com/index.fcgi/wiki/vehicle for example and documentation

//invoked only the first time the model is loaded, or upon reload
function init_chassis(){
  return {mass:7000000, hydro_h1:8, hydro_h2:20};
}

//invoked for each new instance of the vehicle
function init_vehicle(){
    this.set_fps_camera_pos({x:0.0,y:24.6,z:20});
}

//invoked when engine starts or stops
function engine(start){
}

//invoked each frame to handle the inputs and animate the model
function update_frame(dt, engine, brake, steering){
  var f = 4000000*(engine-brake);
  this.extra_force({z:2,y:-70},{x:2000000*steering,y:f});
}

function update_frame (dt, engine, brake, steering, parking) {
// it is important that "parking" is inserted between the return variables
// of the update_frame function

var coeff = 50000;
// coeff determines the intensity of the force
// varies based on boat mass
// (try different values ...)

var vel = this.velocity (true);

this.extra_force ({z: 0, y: 0, z: 0},
{x: -coeff * vel.linear.x * parking, y: -coeff * vel.linear.y * parking});

}

any observation would be greatly appreciated.

Bob.

Navigation

[0] Message Index

[#] Next page

Go to full version