Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Rotate object bone to camera

Author
Message
MateiSoft
12
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 22nd Sep 2019 10:06
Hello Forum,

I have one question: What is the math for making a character rotate it's spine to face the camera?

I tried the simple way like:



But, obviously it didn't worked.

Please, if someone know how to solve the problem, feel free to respond to the thread.

Thank you very much!
www.alexmatei.com
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 22nd Sep 2019 10:57
You can use SetObjectBoneLookAt() and pass the x,y,z position of the camera to it.
MateiSoft
12
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 22nd Sep 2019 14:21
Bengismo,

Thank you for the info!

There is one slight problem: The feet are in front of the camera and the bone orientation is the other way.

Photo attached.

Thank you again!
www.alexmatei.com

Attachments

Login to view attachments
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 22nd Sep 2019 15:33
try rotating the object first
and then fixobjectPivot(objID)

a object by default should face forwards
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
Conjured Entertainment
AGK Developer
19
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 22nd Sep 2019 16:52 Edited at: 22nd Sep 2019 16:56
Quote: "There is one slight problem: The feet are in front of the camera and the bone orientation is the other way."

Then, just spin it around 180 degrees.

SetObjectBoneLookAt()
RotateObjectGlobalY( objID, amount ) or...
RotateObjectBoneLocalY( objID, boneIndex, amount )


RotateObjectGlobalY( objID, 180)
RotateObjectBoneLocalY( objID, boneIndex, 180)

Is it Y, X, or Z ? (for some reason I am thinking Y, but try the others if I am wrong (now you know why I like 2d))
Not sure if Global or Local or bone or not, but this is enough to get you sorted out with the right option.

Cheers

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
MateiSoft
12
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 22nd Sep 2019 17:00
Well, I tried a couple of methods, like, Global or Local but non seems to work.

I rotated the character and fixed it's pivot, and it worked, but, after that, at some point we need to rotate the character in space left or right, sadly, when I try to rotate it facing the camera, it breaks down as shown in the first picture.

This is the whole code:



I can try to upload the soldier.X but I don't know if I am allowed, since it's TGC's object.
www.alexmatei.com
Conjured Entertainment
AGK Developer
19
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 22nd Sep 2019 17:04
Quote: "I can try to upload the soldier.X but I don't know if I am allowed, since it's TGC's object."

No need, I should have him.
I'll try this.

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
Conjured Entertainment
AGK Developer
19
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 22nd Sep 2019 17:21 Edited at: 23rd Sep 2019 01:09
lol I didn't seem to have him on this computer (haven't installed right model pack?) but I had other TGC - FPSC characters ready to try.

SetObjectBoneLookAt(1, 8, getcamerax(1), getcameray(1), getcameraz(1), 0)

Try changing from the spine to a root bone... (change the 8 to a 2)

SetObjectBoneLookAt(1, 2, getcamerax(1), getcameray(1), getcameraz(1), 0)


Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1

Attachments

Login to view attachments
MateiSoft
12
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 22nd Sep 2019 17:29
right, so instead of using rotateobject we use setobjectbonelook at
www.alexmatei.com
Conjured Entertainment
AGK Developer
19
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 22nd Sep 2019 17:31 Edited at: 22nd Sep 2019 17:36
Quote: "right, so instead of using rotateobject we use setobjectbonelook at"

if that is what works... I just used your code and changed the 8 to a 2, figuring that the root bone is what we are after if needing to rotate the whole object

Did that work for you? (many of my models have been rotated 180 degrees in a modeling program, so I am not sure if my model is the same orientation as your soldier.x)

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 22nd Sep 2019 17:32
There is a couple of methods you could use

1>you could calculate the vector that the bone needs to look at


2>You should be able to rotate the object localy around y and keep fixing the pivot.
Depending on how many times you want to do this it may or may not be a good method
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
MateiSoft
12
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 22nd Sep 2019 17:35
well, I still need to have the spine rotated where the camera is so:



Still facing the wrong direction. I tried adding + 180, but it gives weird rotations
www.alexmatei.com
MateiSoft
12
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 22nd Sep 2019 17:39
btw, if you have GameGuru, you can find it there
www.alexmatei.com
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 22nd Sep 2019 17:43 Edited at: 22nd Sep 2019 17:45
Why are you using -GetCameraX() ??

and his spine bone is either 10(spine) or 18 for his neck.

Try this code....this rotates his upper body to face the camera. Use arrow keys to move the camera




If you want to rotate the whole model to face the camera (rather than just the bone) then use SetObjectLookAt

EDITED FOR TERRIBLE SPELLING....
MateiSoft
12
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 22nd Sep 2019 17:51
Bengismo,

Yes, that worked. I'll test it further in my project and see if something comes up.

Thank you all for the help!
www.alexmatei.com
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 22nd Sep 2019 17:54 Edited at: 22nd Sep 2019 17:57
and if you have to keep setting the pivot after rotations, I did this extensively in BlockLifter 3D which
is in games pack 1 and runs well on a really old cheap phone. So I don't see performance loss doing
it that way


edit bengismo cracked it
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
MateiSoft
12
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 22nd Sep 2019 18:04
Fubarpk,

I understand. That's good to know.
www.alexmatei.com

Login to post a reply

Server time is: 2024-11-22 17:01:17
Your offset time is: 2024-11-22 17:01:17