simple camera rotation problem

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
jinxtengu
Posts: 83
Joined: Wed Oct 14, 2009 2:05 pm
Contact:

simple camera rotation problem

Post by jinxtengu » Wed Feb 19, 2020 7:36 am

Hi,
I Have yet to finish any long games using z game editor but I am very close with 2
promising projects, but I have had a few setbacks which is why it's taken so long. Anyway, there is a bit of code that has been bugging me for the last year or so, since I know it is inadequate, and basically a poor solution. I believe It would be quite easy to fix for someone who understands trigonometry better than myself.

so let me explain the problem.
I have an engine for a 3rd person game,
on the "on update" I have two keypress functions for rotating both the view and the player model,
for left and right keys.
the app.camerarotation.y= is set to a value called dir and dir is set on update to
dir-=dspeed;
dspeed is set to a value on pressing the arrowkeys, thus rotating the camera view.
This all works as it should.
The player model is set to "currentmodel.rotation.y+=0.0006673;"
this is to set the players model to rotate the same as the camera direction, however
this is a totally arbitrary variable that I only came to through trial and error.
Superficially it appears to keep the player model rotating in line with the rotation of the camera
but I know it must be slightly out of syc, so if we spin the camera around say 100 times
in one direction then a disparity between the direction that the main character model is
facing and the direction of the main camera is likely to be visible.
So basically I would like to know how to make the main character model
in this third person game, rotate in accordance with the rotation of
the main camera.
I assume the code needed would be something simple like
(on the Onupdate of the player model)
"Currentmodel.rotaion.y=Dir/??"
this is where some trigonometric functions should probably come into play, but I
can't seem to figure it out. If someone could please assist me with working out this
problem, I would be very grateful.
:)



EDIT
-----------------------------------------------
I have solved this problem.
all I needed to do was
Currentmodel.rotation.y=dir/-1;

But I do have one other question, how do we invert a value, to turn it from a positive to
a negative and vice versa?

User avatar
Kjell
Posts: 1721
Joined: Sat Feb 23, 2008 11:15 pm

Re: simple camera rotation problem

Post by Kjell » Wed Feb 19, 2020 12:01 pm

Hi jinxtengu,
jinxtengu wrote:
Wed Feb 19, 2020 7:36 am
But I do have one other question, how do we invert a value, to turn it from a positive to
a negative and vice versa?
The simplest method is to just use put a negative sign in front of your variable, but any of these will work ...

Code: Select all

value = -value;
value = 0-value;
value *= -1;
value = value*-1;
value /= -1;
value = value/-1;
K

jinxtengu
Posts: 83
Joined: Wed Oct 14, 2009 2:05 pm
Contact:

Re: simple camera rotation problem

Post by jinxtengu » Thu Feb 20, 2020 4:56 am

Thanks Kjell,
sorry for asking the most obvious questions.
:shock: 8)

Post Reply