AddHavokBallAndSocketConstraint Questions

Post » Mon Nov 19, 2012 10:22 am

Hello,

I have a big object with a small one attached to it through AddHavokBallAndSocketConstraint. I can apply ApplyHavokImpulse to the big one without problems and the small one tags along. But if I apply ApplyHavokImpulse to the smaller one, the bigger object doesn't move. The small one sviwels like crazy, so it receives the force, and they still stay attached... Now, the big object has a mass of 5000, and the small one has a mass of 5, so it makes sense that it doesn't work. So I tried to up the mass of the small one to 10000, and still no effect. I also tried to reverse the AddHavokBallAndSocketConstraint function, so that the small object is the first parameter, and still nothing.

How can I tell the engine that I want preference to one specific object? How does this work?
User avatar
Siobhan Wallis-McRobert
 
Posts: 3449
Joined: Fri Dec 08, 2006 4:09 pm

Post » Mon Nov 19, 2012 8:42 pm

How can I tell the engine that I want preference to one specific object? How does this work?
I don't think you can.

One question, you don't say what offsets you're passing into the call. Is the constraint centred on the large object, the small one, or somewhere between the two? That might have some bearing on the odd behaviour you're seeing. Another thing that might have something to do with it is the physics data in the .nif files of the two objects; do they both have the same OL_ layer settings; do they have the same inertia matrix and linear/angular damping settings; are they both activators, pieces of furniture or movable statics, or are they different types of object?

And what impulse force are you using, along what sort of vector?

Sorry, lots of questions with no actual help, but something in there may be significant. If all else fails, try just increasing the impulse force when pushing the small item.

Ah, yes, does either object have the 'Don't Havok settle' box ticked in their edit box in the CS?
User avatar
Robert Jackson
 
Posts: 3385
Joined: Tue Nov 20, 2007 12:39 am

Post » Mon Nov 19, 2012 1:55 pm

Thanks for the help andyw,

I'm moving a boat forward through ApplyHavokImpulse. The problem is that I can't turn it like if using TranslateTo, and I can't apply ApplyHavokImpulse to just a node to force rotation, so I had the idea to attach another object (a basket for testing) to a node created at the front of the boat (will be moved later to the back) and apply a lateral impulse to it with the hopes to turn the ship. I can't use SetAngle(), as that looks ugly for the player...

I can ApplyHavokImpulse to the basket just fine, but it just swivels to the side of the impulse without any effect on the ship. If I apply a very strong force, the basket seems to detach and fly a distance before reattaching again at the ship. I have tried with magnitudes up to 200.000. To move the boat forward, albeit slowly, it is more than enough with a magnitude of 200, and the basket tags along nicely.

So, the basket is attached to a node at the front of the ship without any other offset (right at the most forward tip). Both objects have almost the same nif settings, the most noticeable difference being the mass (ship 5000, basket 5). I know that the basket mass should never be able to move the ship mass, but upping the basket mass to 10000 didn't help either. No object has the "Don't Havok settle" setting enabled.

I'm calling the function like this:
	If KeyCode == 75 ;RIGHT - Num4		AngleZ = Self.GetAngleZ()		Self.ApplyHavokImpulse(Math.Sin(AngleZ)+60, Math.Cos(AngleZ), 0.0, 200000)	EndIf

At the moment I have this settings in the ship nif file, and the basket is very similar but the mass, friction, and the "Unknown TimeFactor or Gravity" settings:
----------------------------
Layer: OL_ANIM_STATIC
Mass: 5000
Inertia: m11: 1802
Inertia: m22: 180.2
Inertia: m33: 1802
Linear Damping: 0.5
Angular Damping: 0.0498
Unknown TimeFactor or Gravity 1: 0.0010
Unknown TimeFactor or Gravity 2: 0.0010
Friction: 0.1
Restitution: 0.3
Max Linear Velocity: 104
Max Angular Velocity: 31
Penetration Depth: 0.15
Motion System: MO_SYS_SPHERE
Quality Type: MO_QUAL_MOVING
User avatar
latrina
 
Posts: 3440
Joined: Mon Aug 20, 2007 4:31 pm

Post » Mon Nov 19, 2012 2:11 pm

Should work, that's almost exactly the setup I use for my flying machine mod.

No need to increase the basket's mass above 5, that'll just increase the force you need to apply to get the ship turning. You might try having a small offset from the attachment node on the ship, so the basket's collision mesh doesn't touch the attachment node's, but have a zero offset from the basket so the actual socket is at the centre of the basket (like having a short pole from the prow of the ship with the basket spinning at the end :)). Also, double-check your settings on the attachment node's physics object (I'm sure it also needs a rigid-body) to be certain it isn't static.

Ah, maybe some details about exactly how your node on the ship is set up? I found my attachment nodes would just fall off unless their rigid-bodies were connected to the flying machine's rigid body with a constraint (applied in Blender and corrected in NifSkope) - if you're using a simpler setup and can get it to work you might teach me a thing or two :D!

My flying machine mod is http://skyrim.nexusmods.com/mods/19741, feel free to have a look and see how it works.

You might need to apply repeated impulses to the basket to get the ship rotating, and I noticed you have (I think) the Y rotation inertia reduced. I'm pretty sure m33 is the Z rotation inertia, and reducing that in relation to X and Y might help the ship to turn.

Anything I'm not saying clearly, or seem to just be babbling about, let me know and I'll try and get my words straighter :).
User avatar
Kat Ives
 
Posts: 3408
Joined: Tue Aug 28, 2007 2:11 pm

Post » Tue Nov 20, 2012 12:48 am

I added an offset to the basket so that it isn't in contact with the ship, but I added it on the AddHavokBallAndSocketConstraint function. It doesn't collide with the ship now and hangs in the air. I also equalized m11, m22, and heavily reduced m33. The inertia matrix I don't understand at all. I have tried hard to understand the formulas on the web, but I just don't get it, so I semi-invented the numbers... Now I have m11: 1802, m22: 1802, and m33: 180.2. The basket has a rigid body and reacts to the impulses.

It still doesn't turn. Might it be because the offset has to be in the Nif's node rather than in the function?

I downloaded your mod and it's awesome! Had a lot of fun flying it around! Will later check inside to see if I can learn from it!

What I'm trying should be simpler though. I have the ship set up so that it sinks really slow, and keep it afloat with little constant impulses along the z axis. Movement is similar, as soon as the player presses the forward key, the boat get's an impulse forward. Turning is on the works... And I won't have up and down movement.

I never got Blender to work right with Skyrim, and I don't have any idea how to model anyway, so I'm massacrating the vanilla Long Boat nif. I branch copied a couple of assets from the Katariah vanilla ship model. Per example, I just copied the Anchor Wheel model from the Katariah and pasted it inside the node that contains the havok info in the ship. I repositioned it and scaled it for the long boat at the front of the ship, with hopes to use it later. It is here where I have attached the basket for testing purposes. The constraint applied with AddHavokBallAndSocketConstraint holds well. But it is inside the ship, so this might be causing the no turning issue...

I tried creating empty nodes under the vanilla node with the havok and adding to them the bhkCollisionObject and bhkRigidBodyT nodes to attach more things, but this doesn't seem to work. The nif saves fine, but I get a crash in game. The trick seems to work only if I copy a full vanilla object.

The player can walk fine along the boat while it's moving, although dropping apples on board destabilizes everything. I'll have to counter this probably somehow... The other problem I have is that fishes stop the ship, but I'm solving this with a trigger around the boat that deactivates them as it passes. Here I'm just stuck with the trigger not wanting to follow the boat.

And you're being very clear and very helpful! I'm noticing with your posts many things that I definately can make better! So thanks again! I'm going to look now into your mod to see if I can solve it with it as an example, although I won't be able to solve anything with blender and will have to keep working just with NifScope and scripts.
User avatar
Josh Dagreat
 
Posts: 3438
Joined: Fri Oct 19, 2007 3:07 am

Post » Mon Nov 19, 2012 2:37 pm

The inertia matrix I don't understand at all. I have tried hard to understand the formulas on the web, but I just don't get it, so I semi-invented the numbers...
I'm so glad it isn't just me :D!

Now I have m11: 1802, m22: 1802, and m33: 180.2. The basket has a rigid body and reacts to the impulses.
The node in the ship .nif which the basket is attached to... does that have a rigid body?

It still doesn't turn. Might it be because the offset has to be in the Nif's node rather than in the function?
Having the offset in the AddHavokBallAndSocketConstraint function will work just fine. Should work just fine...

I downloaded your mod and it's awesome! Had a lot of fun flying it around! Will later check inside to see if I can learn from it!
Glad you like it :D. Feel free to use any part of it or ideas from it as needed.

What I'm trying should be simpler though. I have the ship set up so that it sinks really slow, and keep it afloat with little constant impulses along the z axis. Movement is similar, as soon as the player presses the forward key, the boat get's an impulse forward. Turning is on the works... And I won't have up and down movement.
Should be fun when it's finished, I look forward to it. Does it rock/bob at rest, or in motion? It should be possible to get it to float without nudges. The prisoner cart does (though maybe not with someone standing on it.

I never got Blender to work right with Skyrim, and I don't have any idea how to model anyway, so I'm massacrating the vanilla Long Boat nif.
A distressing amount of my time with my mod of late is just figuring out how to get stuff from Blender to Skyrim. I must do a tutorial some day.

I branch copied a couple of assets from the Katariah vanilla ship model. Per example, I just copied the Anchor Wheel model from the Katariah and pasted it inside the node that contains the havok info in the ship. I repositioned it and scaled it for the long boat at the front of the ship, with hopes to use it later. It is here where I have attached the basket for testing purposes. The constraint applied with AddHavokBallAndSocketConstraint holds well. But it is inside the ship, so this might be causing the no turning issue...
Hard to visualise without pictures.

I tried creating empty nodes under the vanilla node with the havok and adding to them the bhkCollisionObject and bhkRigidBodyT nodes to attach more things, but this doesn't seem to work. The nif saves fine, but I get a crash in game. The trick seems to work only if I copy a full vanilla object.

The player can walk fine along the boat while it's moving, although dropping apples on board destabilizes everything. I'll have to counter this probably somehow... The other problem I have is that fishes stop the ship, but I'm solving this with a trigger around the boat that deactivates them as it passes. Here I'm just stuck with the trigger not wanting to follow the boat.

And you're being very clear and very helpful! I'm noticing with your posts many things that I definately can make better! So thanks again! I'm going to look now into your mod to see if I can solve it with it as an example, although I won't be able to solve anything with blender and will have to keep working just with NifScope and scripts.
Heh, quite a few problems that I don't have. Erm... I wonder if random birds flying around can stop a flying machine dead in its tracks :(.
User avatar
Sian Ennis
 
Posts: 3362
Joined: Wed Nov 08, 2006 11:46 am

Post » Mon Nov 19, 2012 7:36 pm

Ok, I think I found my problem with your help...

The nodes added through NifScope don't do the job... The node that had the basket attached did have a rigid body, but set to MO_SYS_BOX and MO_QUAL_FIXED. This allowed it to travel with the boat and stay put with the rocking animation. I changed those and then both the anchor wheel and the attached basket left the ship in a hurry. They still seem to be attached to the ship somehow, just not as intended. It's probably the problem you said you had. If not done through Blender, the constraints don't stick...

I guess I'll have to go find Blender tutorials again and start learning it for good. Meanwhile I will put the proyect on hold, but will make my Blender tests with the ships...

I do like your method of having those 4 buoys sort of like a baloon... I will grab some of your ideas if you don't mind!

Anyway, thank you very much for your help and time, and hope I get the hold on Blender soon...
User avatar
Elizabeth Davis
 
Posts: 3406
Joined: Sat Aug 18, 2007 10:30 am

Post » Mon Nov 19, 2012 10:58 pm

The node that had the basket attached did have a rigid body, but set to MO_SYS_BOX and MO_QUAL_FIXED. This allowed it to travel with the boat and stay put with the rocking animation. I changed those and then both the anchor wheel and the attached basket left the ship in a hurry. They still seem to be attached to the ship somehow, just not as intended. It's probably the problem you said you had. If not done through Blender, the constraints don't stick...
As a stopgap, try doing what I did with the current released version of the flyer - look at the prisoner cart in Nifskope, and find one of the hinge constraints that attaches a wheel to the rest of the cart - it'll be in the wheel node, inside the rigid-body. Select the constraint, there'll be an array of entities, which you set to null. You can now copy that constraint from the prisoner cart and paste it into the ship nif (it'll get dumped outside all other nodes, no worries). In your node that had the basket attached, in the rigid-body of the node, there's a Num Constraints and a Constraints array, get a 1 long array and set it to your newly pasted constraint. Then re-set the constraint's first entity to the sub-node's rigid-body, and the second entity to the ship's main rigid-body. Right-click on your new in-nif constraint, select the Havok A -> B spell, then in the HingeDescriptor divide all values by 10.

You might have to fiddle around with the Axle and Perp values to get it oriented right - http://niftools.sourceforge.net/wiki/Oblivion/Oblivion_Bhk_Constraints page should help.

All this will make sure your ship's attachment point will actually stay attached to the ship, letting your basket drag it and the ship along.

I guess I'll have to go find Blender tutorials again and start learning it for good. Meanwhile I will put the proyect on hold, but will make my Blender tests with the ships...

I do like your method of having those 4 buoys sort of like a baloon... I will grab some of your ideas if you don't mind!

Anyway, thank you very much for your help and time, and hope I get the hold on Blender soon...
Using Blender helps a lot with fiddling around with an attachment point's position and orientation, but isn't actually necessary - especially if it's only a handful of points that you'll just set up once. Blender only supports ragdoll and limited-hinge constraints, so it isn't the ultimate answer :smile:. I'm mostly using it because I'm working on an entirely new flyer model, and Nifskope didn't have the mesh editing facilities I need.

Good luck, hope things move forward. And from side-to-side :biggrin:!
User avatar
Katey Meyer
 
Posts: 3464
Joined: Sat Dec 30, 2006 10:14 pm

Post » Mon Nov 19, 2012 5:58 pm

Well, it worked!!! Thanks again!

I really have to play around with all the settings, as for now the ship is strangely half flying. I did notice that with this system very small impulses are enough to get quite some strength! I'll have to read myself into the constraint link you gave me to achieve something that works well, though. The ship handles quite erratic at the moment. The node I have it attached is translated, so I'm not sure this might be doing something.

But I really like what I'm seeing! Following a little your system, and attaching four nodes (back, front and sides), it should be possible to achieve some nice looking wave effect while maintaining stability.

I do see the need to create nodes specific for this purpose, as every time I apply force to the basket, it pulls the anchor wheel shortly out of place. It returns very fast, like a spring, but stil doesn't look good. I'll try again to create empty nodes containing only the rigid body, or at least attach some invisible object.
User avatar
Bek Rideout
 
Posts: 3401
Joined: Fri Mar 02, 2007 7:00 pm

Post » Mon Nov 19, 2012 11:38 am

Glad I could help :). Good luck with the fine tuning :goodjob:.
User avatar
FITTAS
 
Posts: 3381
Joined: Sat Jan 13, 2007 4:53 pm

Post » Mon Nov 19, 2012 12:10 pm

Ok, more problems to test your patience...

The ship now floats and moves, but quite erratically. I have 4 constraints, font and back, and left and right. All are at the moment underwater, but seem stable. The objects I used to create the constraints on the boat are modified and invisible apples. The constraints themselves I ended copying directly from your dwemer flyer, and modifying them to stabilize the ship (test). The objects attached to the constraints per AddHavokBallAndSocketConstraint are also your flyer nif's, as for testing I supposed these would do the job.

I think I'm having trouble with the ship Nif constraints. They are stable and hold together, but when I apply force to any of the constraint objects, absolutely all other constraints start wobbling like crazy, as if they would be fighting against each other. This causes strange ship movements. Applying force on the back constraint to turn the ship, works, but initially in small jumps, then it starts turning really fast, and then it starts to tip the ship to it's side, stops like if it hit a wall, or starts turning to the other side. Something similar happens with forward movement. As soon as I apply force to the front buoy, it jumps a couple of times and then starts moving forward and turning right, left and down, sinking the ship. So something has to be amiss with my constraints in the Nif.

By the way, I had to increase the ship's mass considerably and reduce the mass of your Flyer nif to 0.001 to get the ship stable without any force applied, which also can't be right.

It seems as if my ship's nif constraints where attached with a spring. My nif is different than yours, mostly because it's a boat, but also because the constraints are translated from the center, and yours are created directly at position through blender without any translation. I fear this could be one of the reasons, and the constraints where trying to pull themselves to the center of the ship.

Anyway, I modified (invented) the constraint settings until the ship stopped rotating like crazy, and they now look like this (example front constraint):
Spoiler
Twist A: X 0.0, Y 0.0, Z 1.0, W 0.0
Plane A: X 0.0, Y 1.0, Z 0.0, W 0.0
Motor A: X 0.0, Y 1.0, Z 0.0, W 0.0
Pivot A: X 0.0, Y 1.0, Z 0.0, W 0.0
Twist B: X 0.0, Y 0.0, Z 1.0, W 0.0
Plane B: X -1.0, Y -0.0, Z 0.0, W 0.0
Motor B: X 0.0, Y 1.0, Z 0.0, W 0.0
Pivot B: X 0.0, Y 15.2142, Z 0.0, W 0.0

Rest of values are "0"
Pivot B values are all calculated by the A>B Spell and divided by 10

Could it have something to do with Pivot A and B? Is there a way to have the constraints completely fixed to their node?
User avatar
Ellie English
 
Posts: 3457
Joined: Tue Jul 11, 2006 4:47 pm

Post » Mon Nov 19, 2012 7:32 pm

It works! It seems I had the constraints center of mass misplaced, and also the buoy objects. Now the ship floats, moves, turns, collides great with land, and rocks like a real boat! The player can move around and drop objects on it. The ship is sustained by 4 floating objects (buoys), which keep it floating. The ship is a little hard to control, but that is because it is actually affected by water currents, which slightly fight against your controls. I have now to find out if I can change direction of water currents dinamically to make this more realistic.

The other issue I'm having is the fishes, but I should be able to solve it with a trigger following the ship. Just that the trigger doesn't want to follow the ship with the moveto function. Why could this be?

I'm loving the constraints! With luck I could use this to make working docks and anchors, as at the moment the currents have the ship in constant but slow movement...

The only issue I still have to resolve is that on game load, the ship swivels like crazy until it settles into its desired position. But once settled, all works great!

Thank you soooo much again!!!


[Edit]: By the way, I'm back to using the baskets as buoys, but I did shamefully copy the constraints from your flyer and modified them to suit my boat... Hope you don't mind.
User avatar
Stace
 
Posts: 3455
Joined: Sun Jun 18, 2006 2:52 pm

Post » Mon Nov 19, 2012 7:12 pm

It works! It seems I had the constraints center of mass misplaced, and also the buoy objects. Now the ship floats, moves, turns, collides great with land, and rocks like a real boat! The player can move around and drop objects on it. The ship is sustained by 4 floating objects (buoys), which keep it floating. The ship is a little hard to control, but that is because it is actually affected by water currents, which slightly fight against your controls. I have now to find out if I can change direction of water currents dinamically to make this more realistic.

The other issue I'm having is the fishes, but I should be able to solve it with a trigger following the ship. Just that the trigger doesn't want to follow the ship with the moveto function. Why could this be?

I'm loving the constraints! With luck I could use this to make working docks and anchors, as at the moment the currents have the ship in constant but slow movement...

The only issue I still have to resolve is that on game load, the ship swivels like crazy until it settles into its desired position. But once settled, all works great!

Thank you soooo much again!!!


[Edit]: By the way, I'm back to using the baskets as buoys, but I did shamefully copy the constraints from your flyer and modified them to suit my boat... Hope you don't mind.
Hooray :biggrin:! Sounds brilliant, well done :goodjob:! And of course I don't mind about using the constraints from the flyer - I stole them from the prisoner cart to start with, so how could I object :wink:. But feel free to use anything else, coding or whatever, that's basically what I uploaded it for.

One way to avoid the crazy-swivel might be to use an OnPlayerLoadGame event to put all your scripts into a safe starting mode, and perhaps use SKSE for it's OnMenuOpen/Close events. Do you test for the elapsed time between havok impulses to adjust their strengths? That can give some crazy huge kicks if you don't allow for it - or you may just use fixed strength impulses, which might have the downside of the boat behaving differently on slower/faster PCs or in the presence/absence of script heavy mods.

Any chance of a video in the 'Show us what you're working on' thread over in the mods forum? I'd love a quick glimpse :smile:.

[edit]
No idea about the trigger, I haven't touched those yet, but have you tried translating it? There may be some issue about its OL layers or its type in the CK :shrug:.
User avatar
Erika Ellsworth
 
Posts: 3333
Joined: Sat Jan 06, 2007 5:52 am

Post » Mon Nov 19, 2012 7:06 pm

The ship swivels at the moment that the buoys attach to their nodes, and then comes to it's resting position. It keeps on dancing a bit, as the constraints seem to keep pulling at each other, but this is actually great, as it makes the ship movement very realistic and doesn't jump at all.

I never thought of different PC specs... Actually, I have only two very basic scripts, one for the fish trigger and the other for controlling the ship. This is the one controlling the ship:
Spoiler
float AngleZobjectreference ControllerBuoyLeftobjectreference ControllerBuoyFrontobjectreference ControllerBuoyRightobjectreference ControllerBuoyBackEVENT OnInit()	RegisterForKey(72) ;FORWARD - Num8	RegisterForKey(80) ;BRAKE - Num2	RegisterForKey(75) ;RIGHT - Num4	RegisterForKey(77) ;LEFT - Num6	RegisterForKey(200) ;UpArrow	RegisterForKey(208) ;DownArrow	RegisterForKey(203) ;LeftArrow	RegisterForKey(205) ;RightArrow	ControllerBuoyLeft = Self.PlaceAtMe(AADXControllerBuoy, 1, abForcePersist = true)	ControllerBuoyFront = Self.PlaceAtMe(AADXControllerBuoy, 1, abForcePersist = true)		ControllerBuoyRight = Self.PlaceAtMe(AADXControllerBuoy, 1, abForcePersist = true)	ControllerBuoyBack = Self.PlaceAtMe(AADXControllerBuoy, 1, abForcePersist = true)		bool ControllerBuoyAttach1 = Game.AddHavokBallAndSocketConstraint(Self, "LeftAttachNode", ControllerBuoyLeft, "Testobject1", 0.0, 0.0, 0.0)		bool ControllerBuoyAttach2 = Game.AddHavokBallAndSocketConstraint(Self, "FrontAttachNode", ControllerBuoyFront, "Testobject1", 0.0, 0.0, 0.0)		bool ControllerBuoyAttach3 = Game.AddHavokBallAndSocketConstraint(Self, "RightAttachNode", ControllerBuoyRight, "Testobject1", 0.0, 0.0, 0.0)		bool ControllerBuoyAttach4 = Game.AddHavokBallAndSocketConstraint(Self, "BackAttachNode", ControllerBuoyBack, "Testobject1", 0.0, 0.0, 0.0)EndEVENTEvent OnKeyDown(Int KeyCode)	If KeyCode == 72 ;FORWARD - Num8		AngleZ = Self.GetAngleZ()		ApplyHavokImpulse(Math.Sin(GetAngleZ()), Math.Cos(GetAngleZ()), 0.0, 70)	EndIf	If KeyCode == 75 ;RIGHT - Num4		AngleZ = Self.GetAngleZ() + 90		ControllerBuoyBack.ApplyHavokImpulse(Math.Sin(AngleZ), Math.Cos(AngleZ), 0.0, 100)	EndIf	If KeyCode == 77 ;LEFT - Num6		AngleZ = Self.GetAngleZ() - 90		ControllerBuoyBack.ApplyHavokImpulse(Math.Sin(AngleZ), Math.Cos(AngleZ), 0.0, 100)	EndIfEndEvent

It's really simple, but I'm actually stuck at something quite stupid. In the script, the get angle function doesn't work. It gives the correct value the first time, but all following calls return the starting angle from the ship, doesn't matter which direction it's facing. I have the same with the getposition function. Not sure if it's a bug, something in my code, or if it's because it's constrained. But I just can't spot the error.

I will look into the functions you say to see if I can solve the beginning issue. And about the trigger, nobody could give an answer yet on how to move them, so it might not be possible.

As soon as I have the fish issue sorted, the ship turning and accelerating correctly, and the buoys invisible, I'll post a video.


[Edit]: Oh... Another issue I have is that as soon as I get a bit far from the ship, the havoc stops working and it sinks. As soon as I aproach it again, it refloats... Any way to keep havok enabled all the time for a specific object?

Here are a couple of videos, I might post them later in the thread you mentioned:
http://www.youtube.com/watch?v=YBgFZlvCELQ&feature=youtu.be
http://www.youtube.com/watch?v=Julom_D0rMM&feature=youtu.be
http://www.youtube.com/watch?v=ubGen3-U400&feature=youtu.be
User avatar
Timara White
 
Posts: 3464
Joined: Mon Aug 27, 2007 7:39 am

Post » Mon Nov 19, 2012 5:05 pm

The ship swivels at the moment that the buoys attach to their nodes, and then comes to it's resting position. It keeps on dancing a bit, as the constraints seem to keep pulling at each other, but this is actually great, as it makes the ship movement very realistic and doesn't jump at all.

I never thought of different PC specs... Actually, I have only two very basic scripts, one for the fish trigger and the other for controlling the ship. This is the one controlling the ship:
Spoiler
float AngleZobjectreference ControllerBuoyLeftobjectreference ControllerBuoyFrontobjectreference ControllerBuoyRightobjectreference ControllerBuoyBackEVENT OnInit()	RegisterForKey(72) ;FORWARD - Num8	RegisterForKey(80) ;BRAKE - Num2	RegisterForKey(75) ;RIGHT - Num4	RegisterForKey(77) ;LEFT - Num6	RegisterForKey(200) ;UpArrow	RegisterForKey(208) ;DownArrow	RegisterForKey(203) ;LeftArrow	RegisterForKey(205) ;RightArrow	ControllerBuoyLeft = Self.PlaceAtMe(AADXControllerBuoy, 1, abForcePersist = true)	ControllerBuoyFront = Self.PlaceAtMe(AADXControllerBuoy, 1, abForcePersist = true)		ControllerBuoyRight = Self.PlaceAtMe(AADXControllerBuoy, 1, abForcePersist = true)	ControllerBuoyBack = Self.PlaceAtMe(AADXControllerBuoy, 1, abForcePersist = true)		bool ControllerBuoyAttach1 = Game.AddHavokBallAndSocketConstraint(Self, "LeftAttachNode", ControllerBuoyLeft, "Testobject1", 0.0, 0.0, 0.0)		bool ControllerBuoyAttach2 = Game.AddHavokBallAndSocketConstraint(Self, "FrontAttachNode", ControllerBuoyFront, "Testobject1", 0.0, 0.0, 0.0)		bool ControllerBuoyAttach3 = Game.AddHavokBallAndSocketConstraint(Self, "RightAttachNode", ControllerBuoyRight, "Testobject1", 0.0, 0.0, 0.0)		bool ControllerBuoyAttach4 = Game.AddHavokBallAndSocketConstraint(Self, "BackAttachNode", ControllerBuoyBack, "Testobject1", 0.0, 0.0, 0.0)EndEVENTEvent OnKeyDown(Int KeyCode)	If KeyCode == 72 ;FORWARD - Num8		AngleZ = Self.GetAngleZ()		ApplyHavokImpulse(Math.Sin(GetAngleZ()), Math.Cos(GetAngleZ()), 0.0, 70)	EndIf	If KeyCode == 75 ;RIGHT - Num4		AngleZ = Self.GetAngleZ() + 90		ControllerBuoyBack.ApplyHavokImpulse(Math.Sin(AngleZ), Math.Cos(AngleZ), 0.0, 100)	EndIf	If KeyCode == 77 ;LEFT - Num6		AngleZ = Self.GetAngleZ() - 90		ControllerBuoyBack.ApplyHavokImpulse(Math.Sin(AngleZ), Math.Cos(AngleZ), 0.0, 100)	EndIfEndEvent
Well, you might get problems if you start applying impulses in a fast loop, but with the code like that there won't be an issue.

It's really simple, but I'm actually stuck at something quite stupid. In the script, the get angle function doesn't work. It gives the correct value the first time, but all following calls return the starting angle from the ship, doesn't matter which direction it's facing. I have the same with the getposition function. Not sure if it's a bug, something in my code, or if it's because it's constrained. But I just can't spot the error.
Oh fudgeknuckles! Yeah, I'd completely forgotten about this, or I'd have given you a heads up. When you apply a havok impulse you move the graphics and collision of the object, but not the object's position in the game-space. As far as the engine is concerned it hasn't moved at all. So two problems, one easy (sort of) to fix, the other... um.

First problem - if the boat moves more than a few cells away from its starting location then its parent cell unloads, the boat unloads, and you go for a swim. The solution is a bit quantum. As soon as you start moving the boat with physics, it splits into the 'real' visible physical boat and a virtual 'ghost' boat that stays at the original location and unloads (taking the 'real' boat with it) when its parent cell unloads. You can avoid this by using the translate command to move the 'ghost' boat so it stays in range of the 'real' boat. That's a tricky bit of code because the translate must never complete, but if you just calculate the distance between the two, divide that by 3 or 4 and make the result your translate speed, it'll always take 3 or 4 seconds to cover the distance - then just keep doing that in an OnTranslateAlmostComplete event handler.

Second problem - where is the 'real' boat??? And I've never managed to solve this one :(. See, in my flyer the player is fixed t the flying machine, so I can just use the player's location and angle. But you need the player moving about freely. I think, maybe, you might be able to fix an Invisible Race NPC to the ship and use its location, but I can't remember if even that updates properly, like the player's does.

Err... I'll think about this, do some tests, but if you can come up with a different or better solution, go for it.

I will look into the functions you say to see if I can solve the beginning issue. And about the trigger, nobody could give an answer yet on how to move them, so it might not be possible.

As soon as I have the fish issue sorted, the ship turning and accelerating correctly, and the buoys invisible, I'll post a video.


[Edit]: Oh... Another issue I have is that as soon as I get a bit far from the ship, the havoc stops working and it sinks. As soon as I aproach it again, it refloats... Any way to keep havok enabled all the time for a specific object?

Here are a couple of videos, I might post them later in the thread you mentioned:
http://www.youtube.com/watch?v=YBgFZlvCELQ&feature=youtu.be
http://www.youtube.com/watch?v=Julom_D0rMM&feature=youtu.be
http://www.youtube.com/watch?v=ubGen3-U400&feature=youtu.be
Saw them, like them :).
User avatar
sally coker
 
Posts: 3349
Joined: Wed Jul 26, 2006 7:51 pm

Post » Mon Nov 19, 2012 10:44 pm

Sorry for the late reply, I was out of the country...

Your explanation about the ghost ship explains most of the issues I'm having. It's a real pitty, as it could have been so easy. At least now I know that my CK isn't bugged... I was starting to suspect something like this, as the sound I have looping on the ship didn't follow and stayed at origin. I did look at your code thinking that you must have had the same issue, and did see that all your calls went to the player, but as you said, that's not an option for me. I did test the function MoveToNode(), and it works. It seems that the nodes are still attached to the 3D object, so I can MoveToNode an invisible collision free object to a central node on the ship, and get so my angle and position whenever needed. I didn't test yet, but I suppose that TranslateToRefNode should work also, making the ghost ship follow the 3D ship easier. I can also now get the distance from the ghost ship and the controller object to stop translation before it ends.

So many workarounds might make my mod lag quite a bit though... I'm going to rewrite the code to account for the ghost ship and the invisible object that has to get me my positions and angles...

Oh, and I was really wondering why my ship always left me swimming in the middle of nowhere always at the same distance from the harbor... Now I know, thanks!

I will start testing translating the ghost ship now. Didn't really think it would work, as the ship is MO_SYS_SPHERE, but thank god it does! Will the ghost buoys attached to the ghost ship follow the ghost ship on translation??? I'll test a bit now...
User avatar
naomi
 
Posts: 3400
Joined: Tue Jul 11, 2006 2:58 pm

Post » Mon Nov 19, 2012 10:22 pm

I did test the function MoveToNode(), and it works. It seems that the nodes are still attached to the 3D object, so I can MoveToNode an invisible collision free object to a central node on the ship, and get so my angle and position whenever needed. I didn't test yet, but I suppose that TranslateToRefNode should work also, making the ghost ship follow the 3D ship easier. I can also now get the distance from the ghost ship and the controller object to stop translation before it ends.
Wheee! I never even noticed the ToNode calls. This could make some of my new stuff so much simpler. Thanks :goodjob: :D!
User avatar
Lexy Dick
 
Posts: 3459
Joined: Mon Feb 12, 2007 12:15 pm

Post » Mon Nov 19, 2012 12:47 pm

Glad I could help back a little too!!! :smile:
User avatar
Janeth Valenzuela Castelo
 
Posts: 3411
Joined: Wed Jun 21, 2006 3:03 am


Return to V - Skyrim