Open marcusx2 opened 3 years ago
This is already trivial by few lines of code.
Agreed, this is possible with the current features of the engine.
Re-opening as re-reading unity constraints, there are some features that may be worth writing utility scripts for 🤔 Wouldn't mind seeing a clear example of use though
Yes, it's possible to do code without constraints. Constraints is just a concept to code in a particular way that makes sense in some situations. It's just nice to have. Whenever you want to think of an entity that is constrained to another in some way. Said entity can be constrained by multiple entities, and have a weight to define how much it is affect by other entities. And being able to animate this weight to dynamically change how much an entity is affected by other entities(in terms of position, rotation, scale, etc, depends on what you want to constrain).
I did give some examples: Imagine, for example, making a bullet go from the world to the screen. Or you have a soccer game and you make the ball's position relative to the current player that holds it. In a image tracked augmented reality, this is used a lot to make a GUI that is in world space go to the screen(with a nice transition animation) if the tracked image is no longer in view for example.
The football example is a bit too simple as it's done quite easily by parenting and unparenting the football to the player, or the UI to and from the camera for the AR example
I'm quite intrigued by the weighting system, is there an example of a use case for that?
@yaustar
The football example is a bit too simple as it's done quite easily by parenting and unparenting the football to the player, or the UI to and from the camera for the AR example
You are thinking in a situation where an object is 100% constrained by another. But with the weight system, an object can be 80% constrained to object x and 20% constrained to object y, for example. I can also constrain to the left side of the screen, right side and middle. You can also constrain object Z's position to object X's position and object Z's rotation to object's Y rotation for example. So contrain different things to different objects. When you are talking about parenting, you are constraining the position, rotation, and scale, and potentially other things all to one parent. The constrain system gives you fine grain control over what is constrained and to what(in Unity at least. In Zapworks Studio you always contrain the position, rotation and scale at the same time, but ideally it should work like Unity to give more power and flexibility).
In any case, the cool thing about the weight is animating it. See the video attached below. (I hope it makes it to the timeline dope sheet feature as well).
https://drive.google.com/file/d/1tYBs_grNBJ5Y4RBgsvvPEW4WW-Q9ma3D/view?usp=sharing
This sounds like very specific use cases, with very specific logic implementation, which is all doable now with fairly simple code.
For a design of some system, we ideally want to answer on few things:
Doing anything described above without existing APIs, would require large time investment upfront to design a system. And would not be trivial to do with few lines of code without such APIs.
Like I said, I think constraints enable an alternative way of thinking and coding. Kinda like when you want to do something repetitive you can use recursion if it makes sense. That's the way I see it. In addition, you are also able to see the constraints in action in a timeline by animating the weight. So the constraint logic is previewable in realtime using timelines, which I think is another strong point.
For a design of some system, we ideally want to answer on few things:
- Is it enabling new things.
- Is it only makes life easier by providing a vastly improved alternative.
- Is it very niche or generic in realistic contexts.
- Is it limiting and only covers part of related tasks, or is it generic and does not limit a lot.
- Does it bloats API with some niche things (every kB matters), or it benefits the majority of engine users.
- Does it saves a lot of engineering upfront cost of implementing similar systems by developers.
1- Yes. 2- Yes. 3- Generic. You can use constraints on any circumstance where something is linked to another in some way. 4- It doesn't limit you. 5- I think it would benefit everyone. That's why Unity and Zapworks Studio has it, for example. Maybe other frameworks as well. 6- Depending on what you want to do, using constraints is a lot easier. Just like using recursion is a lot easier if the problem can be thought in terms of recursion easier. It's an alternative way of thinking how to solve a problem, that can be a natural way to solve it and so, be easier.
I thought it would be a great addition, I use contraints very often in frameworks that allow it. Anyways, if you guys don't think it's worth the effort, that's ok. Oh well, bummer I guess.
We haven't closed the issue so we are still evaluating and thinking out loud (hence the request for explicit examples which you kindly provided) to see how much extra value it can give. By doing so, it allows other users to also add their input or provide their use cases for something similar.
Looking at this a bit and wonder if it be more useful as part of the tween library or a set of utility scripts 🤔
Coming back here to give more input. I think one of the best advantages of constraints is when you couple it with real time preview via timeline by animating the weight. I can see in real time a UI in world space going to the screen (typical augmented reality scenario) without having to compile and run to check if it will work as expected.
Ultimately, I think one of the biggest strengths of game frameworks like playcanvas(and Unity, and Zapworks Studio) is the ability to preview gameplay in realtime as much as possible in the editor, to save time. Constraints, coupled with timelines, enhance this power. That's why Unity has it and Zapworks Studio has it, I think.
While you can do everything without constraints with code, I could do that using other frameworks like Phaser, etc. But with PlayCanvas constraint with timelines can be used to preview a significant amount of functionality in real time in the editor. It just make it so much easier, and to me that is one of the selling points of game frameworks with an editor like PlayCanvas, Unity and others. Without being able to preview much on the editor, I don't see the point of using a game framework like this either. Anything that enhances real time preview in the editor is a welcome addition in my book. Add bezier paths to be previewable on timelines as well, etc(but now I'm going off topic).
@Maksims Please take a look at this forum post. You said it is trivial to do what I want with code, could you help me out? Thank you for your time.
Posted example here using lerps: https://forum.playcanvas.com/t/how-can-i-make-something-go-to-the-screen/22283/3?u=yaustar
Hey guys, just uploading a video showing the strength of the constraint system coupled with timeline support. It's the ability to code the game in the editor and preview movement before even getting to run the game. I noticed I talked a lot but didn't show it in action, so here you have it!
https://user-images.githubusercontent.com/5656275/147484494-537584e5-113f-44e1-84a8-7499ae0e52c5.mp4
@leonidaspir
Please see Unity's constraints concept. Zapworks Studio also has this concept and it goes a step further because it allows you to constrain something to world space and also the screen, which is very useful. Imagine, for example, making a bullet go from the world to the screen. Or you have a soccer game and you make the ball's position relative to the current player that holds it. In augmented reality, this is used a lot to make a GUI that is in world space go to the screen if the tracked image is no longer in view for example.
Constraints is a very useful concept that I'd love to see implemented.