imac2018-3d / StoneEdge

The game's main repo.
MIT License
0 stars 1 forks source link

Implement the Camera as defined by the Technical Specs #39

Closed yoanlcq closed 6 years ago

yoanlcq commented 6 years ago

cc @datross. We'll want to copy from your earlier prototype.

Small TODO list for this:

Quoting the technical specs

Conceptually, our camera is represented by only the following variables (from which the transform is computed) :

We list other items we should add :

Mapping input to camera-relative movement

Let s be the speed factor for the hero, ax and ay be the input axes, and cam be the camera’s transform component; Then v, the velocity to give to the hero, may be computed by

var v = Vector3.zero;
v += s * ax * Vector3.ProjectOnPlane(cam.right, Vector3.up).normalized;
v += s * ay * Vector3.ProjectOnPlane(cam.forward, Vector3.up).normalized;
yoanlcq commented 6 years ago

Whoops, the correct algorithm is

var v = rigidbody.velocity;
v.x = 0f;
v.z = 0f;
v += ax * Vector3.ProjectOnPlane(camera.transform.right, Vector3.up).normalized;
v += ay * Vector3.ProjectOnPlane(camera.transform.forward, Vector3.up).normalized;
rigidbody.velocity = v.normalized * s;

To preserve the Y velocity.

datross commented 6 years ago

I added the prototype I did in the project. (TestsScenes/follow camera). I'm gonna adapt this more seriously with the components you mentioned.

yoanlcq commented 6 years ago

Closing because production has ended this afternoon. Thanks everyone!