Compliment, bugs(?) and questions

First of all: guys of PLAYCANVAS you made excellent work! I have to say I know Unity and it was quite easy to get familiar with PLAYCANVAS. Really excellent and thank you for your hard work we can profit from now (hopefully you too by paying accounts).

Im working on a simple game project, nothing special, just to test out PLAYCANVAS…

Bug or not updated documentation(?)
Today I found a difference between documentation and demo about basis mouse input at
http://developer.playcanvas.com/tutorials/beginner/mouse-input/
In this page I found a sample code and within that the sample code “onMouseMove”:
onMouseMove: function (event) {
// Get the current camera Entity
var cameraEntity = context.systems.camera.current

        // Use the camera component's screenToWorld function to convert the
        // position of the mouse into a position in 3D space
        var depth = 10;
        cameraEntity.camera.screenToWorld(event.x, event.y, depth, this.pos);

        // Finally update the cube's world-space position
        this.entity.setPosition(this.pos);
    }

I got an error using that code fragment at line 30: unknown object… (or similar)
The error line: var cameraEntity = context.systems.camera.current

Checking the demo code (tutorial of Mouse Input) on the same side this line differs: var cameraEntity = context.root.findByName(‘Camera’);

With that line my code worked fine. Im sure there is a solution using “current”, just dunno how.

Working with Force
Today I played around with a force on an entity. I thought I made all right: rigidbody attached, set to dynamic….
The force just wasn’t visible on the falling object. Then, by lucky chance, I found a hint in this forum:
Create the force inside the update function.
Doing so the force related is being affected by the force! This confused my. I expected to attach a force only once and thats it. Why do I have to permanenlty refresh the force inside the update function? If so I still could deactivate the force with the deactivate method when not needed. But the question remains: Is it true I have to attach a force (permanently) inside the update function?

If so I have a problem regarding my project: I have a staff (ego perspective) that can be moved left/right and up/down. By clicking a mouse button a ball should be fired out of the staff in the direction of the current x/y angle of the staff. The problem having the force used inside the update function is the following. The ball is flying away from the player but when the player is moving the mouse and changing the angle of the staff it would also affect the flying ball.
But maybe I got the whole force philosophy wrong.

I guess forces are used a lot, so wouldn’t it make sense to offer it inside the Designer as a component?

Is there a way to rename the project name (inside PROJECTS tab)?

Nice to have:

  • Text support (for displaying text (flat, not 3D inside a panel, like Highscore, life, etc.)
  • 2D support in general (for 2D related games)

Nevertheless, I love to work with PLAYCANVAS, you rrrrroooock, thanks a lot!

1 Like

Hi Tayger,
First of all, let me welcome you to the PlayCanvas community. I hope you have a great time learning PlayCanvas.

Secondly, thank you so much for your kind words. It makes me very happy to know that you like what we have built. And hey, if you want to upgrade to a paid account, that would make me even happier! ;o)

So, let me answers some of your points:

The tutorial code was indeed out of sync with the actual project. I have now updated the tutorial page. I’m very sorry about any confusion that this caused you but thanks for bringing this to my attention. By the way, did you know that our entire developer.playcanvas.com site is actually open sourced on GitHub? So you can submit issues against the site there, or even (if you are feeling very keen) submit pull requests. We thought that open sourcing it (as well as the engine itself) would help people get to know the PlayCanvas tech much more easily.

OK, forces. So I think you are thinking about this wrong. Let me explain:

There are two ways to move a rigid body via the physics engine. Either apply an impulse or a force. An impulse is a force applied in an instant. A force is applied over time. Think of it this way, if you apply an impulse, the body will move the same distance regardless of the time since the physics engine was last ‘stepped’ (if your game runs at 60FPS, this will be 16.6ms). However, if you apply a force, the force is applied over the time since the physics engine was last stepped. This is why applyForce must be applied every frame (in the update function) if you want the application of the force to continue over an extended period of time.

This still might not be obvious so let’s consider some practical examples:

Let’s say you want to fire a cannonball from a cannon. The cannonball should really have a large force applied in an instant. So in this case, we would apply an impulse, right? And this is done just once.

Now, let’s say you want to simulate a finger pushing a box across a table. Here a force is being applied over a period of time. In this case, we would apply a force, and do it in the update function that is called every frame. Maybe the finger pushes the ball in the same direction or maybe the force vector changes from frame to frame. You can account for this in the update function.

Does that help at all?

Since forces and impulses are not startup state - they are things that get applied in response to some event, typically. So they’re not such a good fit for the component UI and work much better as script functions.

As for text support, there a bunch of ways of doing HUD/UI stuff. Check out this page on the Answers site.
And as for 2D support, yes, it would be cool to add this to PlayCanvas. Watch this space. :smile:

Thanks!!

Hi Will

I wanted to write sooner but time is running like sand through my fingers. :blush:
Thanks a ton for your detailed information, it helped me a lot for understanding! I guess I intuitively got it right: “impulse” is like a single “push” (blowing at a ballon once) and force is continuous (motor of a car). I just got stuck into applyforce making it work. And yes, I agree, in my case I have to use applyImpulse for what I need it.
For any other readers interested in this topic:

  • Use applyForce in the Update function
  • Use applyImpulse f.e. in the Initialize function

I will have a closer to look at your HUD/UI link, looks really interesting! Good games don’t need text but sometimes it would be nice….

I already was thinking about a paid account. I’m still learning the playcanvas engine. I have a game idea that could be done by the playcanvas engine but I want to finish my current project and to learn more about the engine. As a “solo fighter” (atm) I have no additiional value of a paid account and I have to figure out whats behind a “private” project. On the other hand you might be interested to have your page/tutorials translated into German to reach more users(?). :wink:
I love working with playcanvas and want to dig deeper into it! Thanks again and also for making your engine open source that hopefully brings it even more ahead!
Respectful greetings
Tayger

Yes, currently, upgrading to a Pro account is useful if you want to work with more than 1 other person or if you want to work in private. Currently, any PlayCanvas user can access your projects (but they can’t modify anything of course). We will add other cool functionality in the near future which will also be a good reason to upgrade (but I can’t say what those things are yet).

Thanks for the very kind offer to help with German translation! That’s great. I will have a chat with the team and see if there is this is something you can help us with. :smile: