# Camera Tutorial

**URL:** <https://forum.playcanvas.com/t/camera-tutorial/151>\
**Category:** Showcase\
**Created:** [March 6, 2014, 10:44am UTC](https://forum.playcanvas.com/t/camera-tutorial/151 "2014-03-06T10:44:03Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![pryme8](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/pryme8/32/4564_2.png) [@pryme8](https://forum.playcanvas.com/u/pryme8)\
**Post date:** [March 6, 2014, 10:44am UTC](https://forum.playcanvas.com/t/camera-tutorial/151/1 "2014-03-06T10:44:03Z")

</div>

I made a orbital camera tutorial, just cause…  
[https://playcanvas.com/pryme8/orbit\_tutorial](https://playcanvas.com/pryme8/orbit_tutorial)

Ill make some more here soon…  
If you want to see some more advance camera stuff im working on keep track of:  
[https://playcanvas.com/pryme8/space](https://playcanvas.com/pryme8/space)  
[https://playcanvas.com/pryme8/space/editor/introBoon.js](https://playcanvas.com/pryme8/space/editor/introBoon.js)

---

<div class="post-metadata">

**Author:** ![pryme8](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/pryme8/32/4564_2.png) [@pryme8](https://forum.playcanvas.com/u/pryme8)\
**Post date:** [March 10, 2014, 5:10pm UTC](https://forum.playcanvas.com/t/camera-tutorial/151/2 "2014-03-10T17:10:50Z")

</div>

Im going to post a better version of this tutorial tonight, where Ill do a version with a lot more solid explanation of the calculation in all three dimensions. And a way smoother system… Ill also do this one from scratch so you can follow along.

---

<div class="post-metadata">

**Author:** ![pryme8](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/pryme8/32/4564_2.png) [@pryme8](https://forum.playcanvas.com/u/pryme8)\
**Post date:** [March 12, 2014, 8:30pm UTC](https://forum.playcanvas.com/t/camera-tutorial/151/3 "2014-03-12T20:30:45Z")

</div>

way better Tutorial…  
[https://playcanvas.com/pryme8/space\_flight\_testing/editor/cameraControl.js](https://playcanvas.com/pryme8/space_flight_testing/editor/cameraControl.js)

---

<div class="post-metadata">

**Author:** ![dave](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/dave/32/4558_2.png) [@dave](https://forum.playcanvas.com/u/dave)\
**Post date:** [March 14, 2014, 1:46pm UTC](https://forum.playcanvas.com/t/camera-tutorial/151/4 "2014-03-14T13:46:09Z")

</div>

This is great stuff @pryme8!

One thing I noticed about your coding style though… 😉

You often attach extra values to your entities like this:

```
this.cam = this.entity;
this.cam.property = "some property";

```

It’s actually best to avoid modifying what properties a class has after construction. Javascript engines can optimize classes ([more details](http://www.html5rocks.com/en/tutorials/speed/v8/#toc-topic-hiddenclasses)) if their property list doesn’t change. As soon as you add a property it becomes “deoptimized”.

I would recommend declaring these properties in the Script constructor and then storing them on the script instance. Like this:

```
this.property = "some property";

```

Anyway, aside from that, great video! 🏆

---

<div class="post-metadata">

**Author:** ![pryme8](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/pryme8/32/4564_2.png) [@pryme8](https://forum.playcanvas.com/u/pryme8)\
**Post date:** [March 15, 2014, 5:53am UTC](https://forum.playcanvas.com/t/camera-tutorial/151/5 "2014-03-15T05:53:45Z")

</div>

can you explain that a little more in debth, I think I get what you are saying but it is kinda fuzzy… Um I think I may have fixed what you are speaking of later in the tut, because when you declare them like that it drops a whole bunch of errors!

Im almost positive on the first execution I go back and rename everything to correct conventions, I was just trying to keep the video flowing so I stopped thinking about some stuff like variable names. Thank you for watching it though, I will keep posting more when ever I have time. I will do some modeling and texture tutorials as well, and also how to port mograph generated animations into a baked FBX file that will work on pC.

---

<div class="post-metadata">

**Author:** ![moka](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/moka/32/4559_2.png) [@moka](https://forum.playcanvas.com/u/moka)\
**Post date:** [March 15, 2014, 2:28pm UTC](https://forum.playcanvas.com/t/camera-tutorial/151/6 "2014-03-15T14:28:39Z")

</div>

Regarding JS Objects, when there is a “class” (function for instantiating objects) its fields (this.) will be “indexed” by VM, so behind the scenes it creates “Shadow Class” which is more optimised and precompiled for better performance. But every time you modify class fields, dynamically defining new fields then it does not uses previous shadow class, and makes a new one. This happens behind the scenes, but has good performance increase. So good rule is not to change class fields, or at least have few versions of it but stick to them.

Pretty much same rule applies to variable types - changing variable types on the fly (string to number), is not as good as having two variables in first place.

Hope that makes a bit more clear about the way VM works. There are some youtube talks about “behind the hood in JS”.

---

<div class="post-metadata">

**Author:** ![dave](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/dave/32/4558_2.png) [@dave](https://forum.playcanvas.com/u/dave)\
**Post date:** [March 15, 2014, 9:35pm UTC](https://forum.playcanvas.com/t/camera-tutorial/151/7 "2014-03-15T21:35:37Z")

</div>

A playcanvas Entity is a “class” in javascript. That is, it is created like this:

```
var entity = new pc.fw.Entity();

```

Internally that calls the Entity constructor (and the base class, the GraphNode constructor). These look something like this:

```
var Entity = function() {
    this._guid = pc.guid.create();
    // more member variables...
}

```

The Javascript VM now knows that an Entity has a member called \_guid plus any others that are declared in the constructor. It can make internal optimizations based on this assumption.

If you do this:

```
var entity = new pc.fw.Entity();
entity.anotherProperty = 123;

```

Then the VM can no longer use those optimizations because you have added a property.

In your case you’ve take a reference of the entity into `this.cam` then you add all your member variables to `this.cam` instead of `this`. It is more optimal to declare all the members you are going to need in the constructor:

```
var Orbit3d = function (entity) {
    this.entity = entity;
    //.. declare members here
};

```

Then use those in the rest of your script.

Like I said, it’s not _massively_ important, but it will be more optimal. So it’s worth getting into the habit of it.

---

<div class="post-metadata">

**Author:** ![pryme8](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/pryme8/32/4564_2.png) [@pryme8](https://forum.playcanvas.com/u/pryme8)\
**Post date:** [March 16, 2014, 1:01am UTC](https://forum.playcanvas.com/t/camera-tutorial/151/8 "2014-03-16T01:01:48Z")

</div>

ill keep that in mind from now on! most likely do it like this.cam = {};

---

<div class="post-metadata">

**Author:** ![Konson](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/konson/32/30614_2.png) [@Konson](https://forum.playcanvas.com/u/Konson)\
**Post date:** [March 29, 2024, 10:06pm UTC](https://forum.playcanvas.com/t/camera-tutorial/151/9 "2024-03-29T22:06:57Z")

</div>

None of your tutorials load, they all get 404’d.

---

<div class="post-metadata">

**Author:** ![LeXXik](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/lexxik/32/6953_2.png) [@LeXXik](https://forum.playcanvas.com/u/LeXXik)\
**Post date:** [March 29, 2024, 11:26pm UTC](https://forum.playcanvas.com/t/camera-tutorial/151/10 "2024-03-29T23:26:16Z")

</div>

This is a a thread from 10 years ago. Please, don’t resurrect them.

---

<div class="post-metadata">

**Author:** ![Konson](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/konson/32/30614_2.png) [@Konson](https://forum.playcanvas.com/u/Konson)\
**Post date:** [March 30, 2024, 4:35pm UTC](https://forum.playcanvas.com/t/camera-tutorial/151/11 "2024-03-30T16:35:52Z")

</div>

I’m sorry, will avoid replying to old posts in the future. I’m trying to learn and I really wanted to read through these tutorials. I suppose there aren’t any archives of old projects, are there?

---

<div class="post-metadata">

**Author:** ![LeXXik](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/lexxik/32/6953_2.png) [@LeXXik](https://forum.playcanvas.com/u/LeXXik)\
**Post date:** [March 30, 2024, 6:06pm UTC](https://forum.playcanvas.com/t/camera-tutorial/151/12 "2024-03-30T18:06:33Z")

</div>

User projects live as long as their owners decide. No archives.

For learning, I’d suggest to look at the official tutorials and documentation pages:

> **[PlayCanvas Developer Site | PlayCanvas Developer Site](https://developer.playcanvas.com/)**
>
> Everything you need to make games and interactive experiences with PlayCanvas.

If you have a question, you can search for an answer on the forum. If the thread is old or can’t find an answer, feel free to create a new topic.
