Home   Help Search Login Register  

Author Topic: SetVelocity  (Read 1976 times)

0 Members and 2 Guests are viewing this topic.

Offline Rommel92

  • Members
  • *
SetVelocity
« on: 23 Jun 2008, 09:51:36 »
Code: [Select]
private ["_vehicle","_speed","_dir","_vel"];

_vehicle = _this;

_speed = 500;

while {true} do {
_vel = velocity _vehicle;
_dir = direction _vehicle;
_vehicle setVelocity [(_vel select 0)+(sin _dir*_speed),(_vel select 1)+ (cos _dir*_speed),(_vel select 2)];
sleep 0.25;
};

The car booms off in the right direction the first time, looks great, then all of a sudden he's teleporting ahead each time, not rolling...

Ie:

AI / Human inside it
-------------------------> ---> --> -> > > > > > > > > > > >
No one
----> ---> --> -> > > > > > > > > > > >

Looks really weird, and nothing like I thought it would? Any ideas guys.

Romm

EDIT:

Tested with:
Code: [Select]
private ["_vehicle","_speed","_dir","_vel"];

_vehicle = _this;


while {true} do {
_vehicle setVelocity [100,100,0];
sleep 0.25;
};
Aswell, same results.
« Last Edit: 23 Jun 2008, 09:57:22 by Rommel92 »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: SetVelocity
« Reply #1 on: 23 Jun 2008, 10:16:26 »
No idea what you are trying to do, anyway:
Code: [Select]
private ["_vehicle","_speed","_dir","_vel"];
_vehicle = _this;

// NOTE THAT 500 m/s for a car is a extreme speed.
_speed = 500;

while {true} do
{
   _dir = direction _vehicle;
   _vehicle setVelocity [(sin _dir)*_speed,(cos _dir)*_speed,velocity _vehicle select 2];
   sleep 0.01;
};

Offline Rommel92

  • Members
  • *
Re: SetVelocity
« Reply #2 on: 23 Jun 2008, 10:30:04 »
Is that the only solution? I was hoping for an actual VELOCITY of the unit, not a kind of very fast setPos (which is how it seems to be working.)

Instead of: ------------------------------------>, > being the car direction and movement, and - indicating smooth movement.
Its moving like a keyframed animation (with 0.01 delay this is hardly noticible, however at 1s, or 0.1 even, its very obvious)
- - - - - - - - - - - - - - - - - >
« Last Edit: 23 Jun 2008, 10:31:54 by Rommel92 »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: SetVelocity
« Reply #3 on: 23 Jun 2008, 10:48:24 »
Is that the only solution?

The only solution for what? Sorry but, while I do my best, my remote mind-reading capability is quite limited (if any).
May you describe what do you want to do or what kind of effect do you want to achieve?.

Offline Rommel92

  • Members
  • *
Re: SetVelocity
« Reply #4 on: 23 Jun 2008, 11:06:29 »
Sorry if I offended you.  :blink:

I was just saying, I've tried all the above already, before you wrote them, and was hoping for a less 'exact same' solution, and clearly from both posts your not understanding what I am trying to get across.

The Car Details:
- Static
- Facing North

I want the Car to move at 500m/s
This would mean:
Code: [Select]
_speed = 500;
The Car Starts off this velocity, moving smoothly North. Upon the SECOND EXECUTION of the above written code (yours, mine, BIKIs), the car begins to JITTER. As in instead of moving SMOOTHLY up the road. It moves like its teleporting, like a bad connection to a server. It instantly looses all speed and continues doing this teleporting. So it appears similar to that of a bad keyframed animation.

Ie:

> (space of 2m) > (space of 2m) >    |||| (teleporting)

Im trying to find a reallistic looking of the car actually rolling along, and keeping up the constant acceleration/velocity of 500 m/s

Which would look like:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  ||||    (smooth)


Now the problem is, I don't want to have to constantly set this velocity constantly (ie not every 0.01s, rather I'd prefer atleast a 2s delay) which logically would be ok, considering the was doing this at initial velocity, but from then it does not roll, it just teleports. Like a setPos.
« Last Edit: 23 Jun 2008, 11:08:33 by Rommel92 »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: SetVelocity
« Reply #5 on: 23 Jun 2008, 12:25:31 »
Of curse you havent offended me  :blink:  :P
But your code is way different than mine (that is what confused me), because you are accelerating the car every time by 500m/s more.
Code: [Select]
_vehicle setVelocity [(_vel select 0)+(sin _dir*_speed),(_vel select 1)+ (cos _dir*_speed),(_vel select 2)];
You get current velocity at each time and then you adds speed. So it starts stopped (0ms) at time T0, at time T1 it moves at 500 m/s (0.25 secs later, and the car is moving supersonic), at time T2 (0.5 secs after starting the script) you add 500m/s more, the car is moving at 1000 m/s, after the first second of your script the car would be moving at 2000 m/s. And I dont think ArmA can handle that.

Offline Rommel92

  • Members
  • *
Re: SetVelocity
« Reply #6 on: 23 Jun 2008, 13:12:44 »
It doesnt work at 5m/s, for that matter, with or without the constant acceleration, which I tried because it was originally on a timer of around 2s, so the acceleration would "jolt" the car back up to full speed, however instead with both of our codes, it simply teleports the car forward unless it is on a delay that is incredibly fast (0.01).

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: SetVelocity
« Reply #7 on: 23 Jun 2008, 13:30:50 »
0.01 for setVelocity is not incredibly fast, in fact, it is even a bit slow as ArmA physics might affect the car at that rate. Check this as a reference for vehicle movements over the ground.

Offline Rommel92

  • Members
  • *
Re: SetVelocity
« Reply #8 on: 23 Jun 2008, 13:44:53 »
Whilst useful, that mad me laugh ... a lot.  :P

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: SetVelocity
« Reply #9 on: 23 Jun 2008, 16:52:20 »
I think the problem here is a little different, maybe?

Basically, giving the car an initial velocity the first time it's set down works : because of ArmA physics being what they are (ever notice how when you shoot an editor-placed car, it sort of "bumps" into the physics engine?). However, subsequent times will not quite work. I found this out when I tried to make a "nitro boost" script for JOHNS_BUGGYS' : basically, trying to give a car that is on the ground, touching it, a velocity does not work!

The solution, if I remember it correctly, is to lift the car a little above the ground, and THEN sending it off - a bit like you'd do with soldiers. Even then, you need to constantly at a very fast loop give it more and more speed, until you want it no longer. Here's teh script in its simple form:

Code: [Select]
//nitroboost.sqf
//Default stuff given to script via addaction
_vehicle = vehicle (_this select 0);
_caller = _this select 1;

//Makes sure the caller is also the driver, and that the vehicle isn't upside down.
if ((_caller !=driver _vehicle) OR (vectorUp _vehicle select 2 < 0)) exitWith {};

//Actual "script" (courtesy of BIKI) -> _speed variable is how much speed is added. _count is for how many hundreds of a second the nitro is run: presently 1 second.

_vel = velocity _vehicle;
_dir = direction _vehicle;
_speed = 10;
_count = 100;

while {_count > 0} do
{
_dir = direction _vehicle;
_vel = velocity _vehicle;
_vehicle setVelocity [(_vel select 0)+(sin _dir*_speed),(_vel select 1)+ (cos _dir*_speed),(_vel select 2) - 1];
_count = _count - 1;
sleep 0.01;
};
_vehicle setVelocity [(_vel select 0)+(sin _dir*_speed),(_vel select 1)+ (cos _dir*_speed),(_vel select 2) - 1];

There's another form of it over at the topic too : BIF

Problems with this is mostly that it completely ignores all laws of physics when it goes over a hill or somesuch, just kind of floating in the air :D Oh yeah, and called with addaction and such, I'm sure you'll figure it out!

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"