Jump to content
Sign in to follow this  
mad_cheese

SetVectorDirAndUp plus AttachTo problem with relative direction

Recommended Posts

Hey guys,

I did a lot of searching, found a lot of threads on the subject but there's a twist that's not included in those threads.

I'm trying to get a mock-style dog attack working. The possibilities are extremely limited, there's very few animations etc.

My idea is: dog runs to target -> distance < 1.7 -> setvectordirandup + attach dog to target (if possible in increments)

The problem is attaching the dog to the target while taking the direction into consideration. I read all the tutorials I could find, Killzone_Kid's was very very clear, but... as far as I understad it does not take the relative directions of object and target into consideration. My understanding of both vectordir and vectordirandup is very small, I tried a bunch of things but could not get it to work correctly. Here's what I have so far (the script assumes the dog is already closer than 1.7m to it's target). It's really all over the place.

DogAttack = {
private ["_dog","_victim","_dirandup"];
_dog = _this select 0;
_victim = _this select 1;
_dirandup = 0;
_dogAslZ = (getposASL _dog select 2);
_dog switchmove "dog_sprint";
_dog allowdamage false;	
[_victim] spawn {
	private ["_victim"];
	_victim = _this select 0;
	sleep 0.3;
	_victim setdamage 0.5;
	if (_victim == player) then {[90] call BIS_fnc_Bloodeffect};
	switch (currentweapon _victim) do {
		case (primaryweapon _victim) : {_victim switchmove "amovpercmsprslowwrfldf_amovppnemstpsraswrfldnon"};
		case ("hgun_P07_F") : {_victim switchmove "amovpercmsprslowwpstdf_amovppnemstpsraswpstdnon"};
		default {_victim switchmove "amovpercmsprsnonwnondf_amovppnemstpsnonwnondnon"};
	};
};

     _dirto = [_victim,_dog] call BIS_Fnc_Dirto;
     _attach = [];
     if (_dirto < 0) then {_dirto = _dirto + 360};
     switch (true) do {
      case ((_dirto >= 0) && (_dirto < 90)) : {_attach = [0.4,1.1,-0.3]};
      case ((_dirto >= 90) && (_dirto < 180)) : {_attach = [0.4,-0.1,-0.3]};
      case ((_dirto >= 180) && (_dirto < 270)) : {_attach = [-0.4,-0.1,-0.3]};
      case ((_dirto >= 270) && (_dirto < 360)) : {_attach = [-0.4,1.1,-0.3]};
    };

for "_i" from 1 to 50 do {
	hintsilent format ["%1 , %2",_dirandup,_dogAslZ];
	_dog setposasl [(getposASL _dog select 0),(getposASL _dog select 1),_dogAslZ + 0.001];
	_dog setVectorDirAndUp [[(vectordir _dog select 0),(vectordir _dog select 1) + _dirandup,(vectordir _dog select 2) + _dirandup],[(vectorup _dog select 0),(vectorup _dog select 1) - _dirandup,(vectorup _dog select 2) + _dirandup]];
	_dog attachTo [_victim, _attach,"pelvis"];	
	_dirandup = _dirandup + 0.001;
	_dogAslZ = (getposASL _dog select 2);	
	sleep 0.01;
};
_dog setVectorDirAndUp [[(vectordir _dog select 0),(vectordir _dog select 1) + _dirandup,(vectordir _dog select 2) + _dirandup],[(vectorup _dog select 0),(vectorup _dog select 1) - _dirandup,(vectorup _dog select 2) + _dirandup]];
_dir = getdir _dog;
detach _dog;
_dog setdir _dir; _dog setformdir _dir;
       _dog switchmove "dog_bark";

for "_i" from 1 to 5 do {
	_victim setdamage (getdammage _victim + 0.1);
	if (_victim == player) then {[(_i * 20)] call BIS_fnc_Bloodeffect};
	sleep 1;
};
};

It's a total disaster, you don't have to bother trying to make much sense out of it. First of all, I guess it might be possible to find an attachto-array that works in the style of BIS_fnc_Dirto, but my math skills are even worse than the script above. Second of all, I'm having trouble to combine SetVectorDirAndUp and Attachto this way. That's why I tried the loop. The dog will do crazy circles like he's trying to breakdance. It's easier off course without using attachto, but it looks ridiculous... The target might be running and will play an animation for falling down, so it looks like the dog kills him by tapping him with his front paws.

Anyways, I think I'm overcomplicating things and thought maybe somebody already knows how to do this. Here's a gif that gives you the idea.

Agif_zps91a6c2e9.gif

Edited by Mad_Cheese

Share this post


Link to post
Share on other sites

Apologies for the bump... My previous post was so messy I can't really be surprised that no one answered.

I managed to boil the problem down to one last issue. I can determine the correct array for the AttachTo command, using BIS_fnc_Relpos and the worldToModel command.

_dog = _this select 0;
_victim = _this select 1;

// Determine the relative direction between _victim and _dog
_dirto = [_victim,_dog] call BIS_Fnc_Dirto;
if (_dirto < 0) then {_dirto = _dirto + 360};
if (_dirto > 360) then {_dirto = _dirto - 360};

// Determine the attachTo array
_height = ((asltoatl (eyepos _victim)) select 2) - 1;
_Worldpos = [[(getpos _victim select 0),(getpos _victim select 1),_height],0.5,_dirto] call BIS_fnc_Relpos;
_Mpos =  _victim worldToModel _Worldpos;

// Attach + SetVectorDirAndUp _dog
_Vdir = vectordir _dog;
_VUp = vectorup _dog;
_dog attachto [_victim,_Mpos];
_dog setVectorDirAndUp [[(_Vdir select 0),(_Vdir select 1) + 0.5,(_Vdir select 2) + 0.5],[(_VUp select 0),(_VUp select 0)-0.5,(_VUp select 0) + 0.5]];
_dog playmove "dog_bark";

Now, my last issue is all within the SetVectorDirAndUp command. The dog is attached to the victim at the correct position. It is also tilted upwards, but will always face the same direction as the victim. It's an acceptable result if the dog is approaching the victim from behind, but only then. I can't use setDir as it reverts setVectorDirAndUp..

If anybody has an idea where my mistake is or how to get the dog to stay facing towards the victim, you will really make my day.

Edited by Mad_Cheese

Share this post


Link to post
Share on other sites

This probably won' t help and I haven't had chance to check the script, but the last time I checked there was a serious bug in attachto.

For set direction/setvector to work after the attach you need to run the attach a second time. I found you only need the attachto you don't need to do the vector twice.

http://feedback.arma3.com/view.php?id=7228

Share this post


Link to post
Share on other sites

oh my god :) YES, it seems like attachTO is bugged indeed. Thanks a million for clearing that up!!!

I tried a variety of ideas in a loop and while the dog does change it's direction while being attached, it also appears that my Array for SetVectorDirAndUp is all wrong and also only works if the dog is facing north.

I'm now testing a different approach with a loop that just uses SetPosASL and BIS_fnc_Relpos in very small increments. Since the victim is forced to fall down by animation, this might just work. Haven't figured it out completely but it already looks a lot more satisfying.

I'd still love to attach the dog though... But anyways, really appreciate that input.

Share this post


Link to post
Share on other sites

Okay, it's getting there. Still needs a lot of tweaking, but given the lack of animations it's somewhat acceptable for now. Hope I'll have more options once the campaign is updated.

I'm glad that the attachto bug came up. Since the animations for a unit falling to the ground always face forwards, i needed to cheat and adjust the victim's direction to the dog's direcetion while the dog makes his jump. This kinda solves the whole issue since the dog will now always be behind the victim.

This is what it looks like now:

Share this post


Link to post
Share on other sites

This is great work buddy, I've been including dogs in my missions but they only look cool walking beside you. Awesome stuff man.

Share this post


Link to post
Share on other sites

That looks great, I messed with a few dog attack scripts but never felt right without an end product.

Share this post


Link to post
Share on other sites

thanks guys!

it really needs lots of polishing, the angle in the video is pretty ideal and there's this thing going on where the dog might do a full 360 spin when attacking.. Looks amazing but It has to go, Roundhouse-bite-ninja-Dog will stay in the closet until his time comes :D

I'll share the script once it's optimized!

As far as SetVectorDirAndUp, not sure if that was explained in the tutorial (it probably was), but I finally realized that after attaching an object to a 'carrier', all the objects vector data is relative to the carrier, not to the attached objects actual world space.

_object setVectorDirAndUp [[0,0.5,0.5],[0,-0.5,0.5]];

Without attaching, _object would face north and be tilted backwards 45 degrees. IN an attached state, _object will be tilted backwards 45 degrees, but it will share the direction of the carrier. So it should be possible to create an array for attaching the dog in the right spot with the right direction, but it will go way beyond my understanding of math. Plus, since the unit is falling forwards, it doesn't make any sense. F2KSel saved me from learning that the hard way. Saved me a lot of time.

Share this post


Link to post
Share on other sites

I think the problem is that when a Unit falls it doesn't change it's vector.

Think of it like a character on the TV when he falls the TV stays vertical only the animation falls.

For units this always returns 1 but for objects the value changes

while {true} do {
hint str (vectorUp player select 2);
sleep 0.1};
};

Share this post


Link to post
Share on other sites
I think the problem is that when a Unit falls it doesn't change it's vector.

That's true.

I got it working. First I made a function to determine the necessary arrays for SetVectorDirAndUp, relative to the dog's direction. This literally vaporized my brain - god, I hate math ;)

Before I could even get that to work properly, I had a brainfart: Since all the vector stuff of an object becomes relative to the 'carrier' once it's been attached to something, I spawned an invisible civilian and attached the dog to it. Works like a charm every time and has less impact on performance. I'll tweak it more and share in a few days.

Share this post


Link to post
Share on other sites

Hi Mad_Cheese,

Nice idea with the dog! Not sure if you solved your problem already, if not probably this will help:

http://forums.bistudio.com/showthread.php?160330-Scripting-Discussion-%28dev-branch%29&p=2679302&viewfull=1#post2679302

As far as i understood you're still having problems with setVectorDirAndUp from the dog. Try to use the function rotateAroundOwnAxisX ( or if you want other rotations: rotateAroundOwnAxisY, rotateAroundOwnAxisZ ) to adjust your dog how you want.

Hope the Roundhouse-bite-ninja-problem is history now ;)

Enjoy it!

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×