Outerra forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Outerra Tech Demo download. Help with graphics driver issues

Author Topic: Mooring or Anchoring Watercraft  (Read 1104 times)

Bob425

  • Jr. Member
  • *
  • Posts: 45
Mooring or Anchoring Watercraft
« on: December 28, 2017, 05:30:45 am »

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.
Logged

andfly

  • Full Member
  • ***
  • Posts: 221
Re: Mooring or Anchoring Watercraft
« Reply #1 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.   :)
Logged
I do not know the English language. I use Google Translate. I hope it's all understandable.

Bob425

  • Jr. Member
  • *
  • Posts: 45
Re: Mooring or Anchoring Watercraft
« Reply #2 on: December 28, 2017, 03:43:15 pm »

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.   :)

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.
Logged

andfly

  • Full Member
  • ***
  • Posts: 221
Re: Mooring or Anchoring Watercraft
« Reply #3 on: December 29, 2017, 11:05:00 am »

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.
Logged
I do not know the English language. I use Google Translate. I hope it's all understandable.

Bob425

  • Jr. Member
  • *
  • Posts: 45
Re: Mooring or Anchoring Watercraft
« Reply #4 on: December 29, 2017, 01:49:32 pm »

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.

Logged

andfly

  • Full Member
  • ***
  • Posts: 221
Re: Mooring or Anchoring Watercraft
« Reply #5 on: December 29, 2017, 02:16:04 pm »

You have defined 2 times a function with the exact same name (update_frame) ....
this is not allowed in any programming language ...

You must delete the lines:

function update_frame(dt, engine, brake, steering){
var f = 4000000*(engine-brake);
this.extra_force({z:2,y:-70},{x:2000000*steering,y:f});
}

and enter the commands:
var f = 4000000*(engine-brake);
this.extra_force({z:2,y:-70},{x:2000000*steering,y:f});


within the update_frame function that you define immediately after.

The presence of two commands this.extra_force, in a function, is not an error!
the model will simply be subject to two forces instead of just one !!

The model does not float for any particular property ...
The execution of the script stops (due to the error) and the simulation stops before the ship manages to touch the surface of the water.
« Last Edit: December 29, 2017, 02:19:36 pm by andfly »
Logged
I do not know the English language. I use Google Translate. I hope it's all understandable.

Bob425

  • Jr. Member
  • *
  • Posts: 45
Re: Mooring or Anchoring Watercraft
« Reply #6 on: December 30, 2017, 06:08:18 am »

All sorted now, thank you Andfly.

I was getting the same problem with the boat in mid air, so I went to the eng log file and got the following:-

ERROR: vehicle::init_chassis
file:///Outerra/packages/Bob425/Rotterdam/Rotterdam.js(32): SytaxError:
Duplicate data property in object literal not allowed in strict mode
(ot::vehicle_physics::load_script(): )

Line 32 read:-
this.extra_force ({z: 0, y: 0, z: 0},

when of course it should have been:-
this.extra_force ({x: 0, y: 0, z: 0},

All is now fine, and my thanks go to you for all the trouble you have taken to help me.
(Programming does not come easy when you are nearly eighty years of age)

Bob.
Logged

andfly

  • Full Member
  • ***
  • Posts: 221
Re: Mooring or Anchoring Watercraft
« Reply #7 on: December 30, 2017, 11:49:13 am »

Acc ... Bob ...     :o

I am extremely admired of your ability to establish a (and profitable) confrontation with a reality in frenetic progress such as the use of computer systems ...
And not just as a simple user, but with the intention of mastering them with programming ...
It is a world that creates difficulties even for the children who were born there.
For those who have reached a more mature age constitutes (in most cases) an insurmountable obstacle!
My admiration, above all, to the ability to thrill and excite you that is sensible by the stubbornness with which you wanted to "go to the bottom" in solving the problem of the boat.
I always thought that only this ability is the true index of a person's age ... beyond what the personal documents say ...


I apologize for my error in haste that has created difficulties for you.
Actually I wrote a "z" instead of an "x", but you have solved it without problems!

I'm glad you're OK now.
If you need further advice or information, do not hesitate to use this forum.

It will be a pleasure to contribute to fuel the enthusiasm for the simulation and for this magnificent engine-outerra!   :D :D
Logged
I do not know the English language. I use Google Translate. I hope it's all understandable.

Bob425

  • Jr. Member
  • *
  • Posts: 45
Re: Mooring or Anchoring Watercraft
« Reply #8 on: December 30, 2017, 01:52:02 pm »

Thank you for your kind words, Andfly.

z & x are next to each other on the keyboard, so it is a easy mistake to make!
Logged