Jump to content

I need a Pro-Scripter/Mathematician's Help on this one...


TallgeeseIV

Recommended Posts

Whew, where to begin... ok. i'm trying to create an inverse relationship (i think that's what it's called?) between the X and Y angle of an object BASED on its Z angle. essentially i'm trying to make an object tilt forward all the time, regardless of the direction its facing, and obviously its X and Y angles are relative to the world axis, not its own, so i need an equation for keeping the angles set to keep it tilted based on its Z... Has anyone done this before in their mod, or a mod they've played? I'm afraid my math skills are quite poor, haha. Edited by TallgeeseIV
Link to comment
Share on other sites

Ok, I made this nifty table to illustrate what i'm trying to do. (i know it looks like i'm bad at scripting, i wrote this in notepad using similar syntax so as not to confuse myself, this isn't a script)

 

PlayAngleZ == 0 / 360 (Rotating on X-Axis Only)
TiltX = 45
TiltY = 0

PlayAngleZ == 45
TiltX = 22.5
TiltY = 337.5

PlayAngleZ == 90 (Rotating on Y-Axis Only)
TiltX = 0
TiltY = 315

PlayAngleZ == 135
TiltX = 337.5
TiltY = 337.5

PlayAngleZ == 180 (Rotating on X-Axis Only, Reverse Direction)
TiltX = 315
TiltY = 0

PlayAngleZ == 225
TiltX = 337.5
TiltY = 22.5

PlayAngleZ == 270 (Rotating on Y-Axis Only, Reverse Direction)
TiltX = 0
TiltY = 45

PlayAngleZ == 315
TiltX = 22.5
TiltY = 22.5

 

PlayAngleZ is the object's Z angle. Tilt X and Tilt Y are its X and Y Angle.

 

each tier is what the X and Y should be When Z is what is listed to keep it tilted 45 degrees. I need an equation for both X and Y, that uses Z to calculate X and Y. the equation has to prove true for each tier i listed there AND everything in between. any help?

Link to comment
Share on other sites

I think I had done this before. I'll see if I can find it, otherwise I'll work it out again.

 

That would be AWESOME, thank you so much! I spent 4 hours racking my brain over this last night and ended up with a headache, hahaha

Link to comment
Share on other sites

Actually, depending on what you ultimately want to do, the problem may be a lot simpler than what you're looking for above. Namely, if you're only interested in doing this on one or a few known objects. Because of how SetAngle works, if the particular mesh is oriented the right way you could simply set the x angle to 90, set the z angle to the desired "tilt" (45 in your example), and then the heading (the "facing" angle) would be controlled by the y angle alone. You would just need to set the object's y angle to the desired heading plus or minus 90 (depending on how the mesh was set up), while maintaining the x and z angles.

 

I know that probably makes no sense at all without some visual aids, but if you want to be able to do this with any arbitrary object you'll need the formulas you're looking for above anyway. So could you give a little more detail? (I haven't yet found my old work.)

Link to comment
Share on other sites

Actually, depending on what you ultimately want to do, the problem may be a lot simpler than what you're looking for above. Namely, if you're only interested in doing this on one or a few known objects. Because of how SetAngle works, if the particular mesh is oriented the right way you could simply set the x angle to 90, set the z angle to the desired "tilt" (45 in your example), and then the heading (the "facing" angle) would be controlled by the y angle alone. You would just need to set the object's y angle to the desired heading plus or minus 90 (depending on how the mesh was set up), while maintaining the x and z angles.

 

I know that probably makes no sense at all without some visual aids, but if you want to be able to do this with any arbitrary object you'll need the formulas you're looking for above anyway. So could you give a little more detail? (I haven't yet found my old work.)

 

Ah, I'll experiment with the heading angle function next then.

 

anyway, basically, i have a floating chair. it's going to be a different model eventually but for now it's a chair while i'm getting the scripting done. the chair needs to remain tilted forward at a set angle (i'm starting with 45 degrees forward, relative to itself, but i need that to be a variable eventually as well, i'll figure that part out) the chair is scripted to change it's z angle with the player's z angle, so it spins in place as the player looks around. i need the chair to stay tilted forward, facing the direction the player is facing, no matter what direction the player is facing.

 

i realized this same effect could be applied to create a 3 dimensional compass as well, that points up or down to your target, i might work on that if i get this working.

Link to comment
Share on other sites

Ok, then you'll probably have an easier time the way I explained. Will you be editing the mesh yourself? I'm pretty sure the orientation you'll want is to have the model laying on its left side, with the top pointing along the negative y-axis. That way when you position it in-game, setting x angle to 90 will make it upright, the z angle will tilt it (+z will tilt forward/face-down, -z will tilt backward/face-up), and you'll set the y angle to heading - 90. So your script to make it spin could be as simple as:

 

set HeadingAngle to Player.GetAngle z - 90
MyObject.SetAngle y HeadingAngle

 

I'm gonna modify a mesh real quick to make sure that's all correct.

 

EDIT:

Alright, I had to turn a couple things around. Have the model on its left side with top pointing along the positive y-axis. Then in script keep the x angle at -90, z angle is tilt (+z will tilt forward/face-down, -z will tilt backward/face-up), and y angle will be heading - 90.

 

Here's a little more script:

 

float fHeading
float fTilt

Begin GameMode
set fHeading to Player.GetAngle z - 90
MyObject.SetAngle x -90
MyObject.SetAngle y fHeading
MyObject.SetAngle z fTilt
End

Obviously you'd need to set the value of fTilt somewhere (either once, or variable based on whatever), or replace it with a hardcoded value. If your model has collision, you'll want to be setting the x and z angles every frame like that (and also x, y, z position - I left that out as well), otherwise it may fall or tilt by itself.

 

EDIT2:

If you want to try this out, I attached the test model I used. It's the Action Abe model oriented the way I described. I have it as a replacer, so there's no need to add it in the GECK, just use the vanilla object MS06ActionAbe (00045258). By the way, Feng Shui (in rotation mode with visible axes on) is helpful to visualize and figure this kind of stuff out ;).

Edited by HugePinball
Link to comment
Share on other sites

hmm, not a bad solution, but it's too much of a workaround. this object tilts in other directions and changes positions and such, based on other criteria in the script, which makes it very confusing, haha

 

EDIT: i think i'm getting close to the proper equation though. i'll post what i came up with when it works every time.

 

EDIT Again: Ok, I got the X axis tilting properly, working on Y now, shouldn't be too hard, just have to figure out the difference from x's formula.

 

For anyone interested:

 

		set TiltAngleZ to PlayAngleZ

	If TiltAngleZ == 360
		set TiltAngleZ to 0
	ElseIf TiltAngleZ > 180
		set TiltAngleZ to TiltAngleZ - 180
	EndIf

	If TiltAngleZ >= 0 && TiltAngleZ < 90
		set TiltX to 45 - ((TiltAngleZ / 45) * 22.5)
;			set TiltY to 0 - ((TiltAngleZ / 45) * 22.5)
	ElseIf TiltAngleZ >= 90 && PlayAngleZ <= 180
		set TiltX to 45 - ((TiltAngleZ / 45) * 22.5)
;			set TiltY to (360 - (TiltAngleZ / 2))
	EndIf

 

notice the Y ones are semicolon'd out, i haven't finished yet, the ones there definitely don't work.

 

EDIT AGAAAIN: scratch that. back to the drawing board

Edited by TallgeeseIV
Link to comment
Share on other sites

IT WOOOOORKS!!!!!!!!!!

 

here's the segment of script i wrote for anyone interested:

 

		set TiltAngleZX to PlayAngleZ
	set TiltAngleZY to PlayAngleZ

	If TiltAngleZX > 180.0
		set TiltAngleZX to TiltAngleZX -180.0
	EndIf

	If TiltAngleZY < 90.0 || TiltAngleZY > 270.0
		set TiltAngleZY to TiltAngleZY - 180.0
			If TiltAngleZY < 0
				set TiltAngleZY to 360 + TiltAngleZY
			EndIf
	EndIf


	If PlayAngleZ >= 0.0 && PlayAngleZ < 90.0
		set TiltX to 45.0 - ((TiltAngleZX / 45) * 22.5)
		set TiltY to (360.0 - ((TiltAngleZY - 90.0) - ((TiltAngleZY / 45) * 22.5)))

	ElseIf PlayAngleZ >= 90.0 && PlayAngleZ < 180.0
		set TiltX to 45.0 - ((TiltAngleZX / 45) * 22.5)
		set TiltY to (TiltAngleZY - 90.0) - ((TiltAngleZY / 45) * 22.5)

	ElseIf PlayAngleZ >= 180.0 && PlayAngleZ < 270.0
		set TiltX to (360.0 - (45.0 - ((TiltAngleZX / 45) * 22.5)))
		set TiltY to (TiltAngleZY - 90.0) - ((TiltAngleZY / 45) * 22.5)

	ElseIf PlayAngleZ >= 270.0 && PlayAngleZ < 360.0
		set TiltX to (360.0 - (45.0 - ((TiltAngleZX / 45) * 22.5)))
		set TiltY to (360.0 - ((TiltAngleZY - 90.0) - ((TiltAngleZY / 45) * 22.5)))
	EndIf


	If TiltX < 0.0
		set TiltX to 360.0 + TiltX
	EndIf

	If TiltY < 0.0
		set TiltY to 360.0 + TiltY
	EndIf

	PlacedObject.SetAngle X TiltX
	PlacedObject.SetAngle Y TiltY

Edited by TallgeeseIV
Link to comment
Share on other sites

Well, THAT didn't work... I couldn't figure out how to modify the rotation with the way i did it so i'm using your method now... problem is, now it's nearly impossible to make it rotate left and right of the direction you're facing. i literally need pitch, roll and yaw from this thing and i can't get the stupid math right... i've literally been staring at this and trying things for 18 hours with no luck...

 

does ANYONE know how to make an object rotate on all 3 axis' regardless of what direction it's facing? i'm ready to die now....

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...