Is it possible to define more accurate custom shape collision box rather than rectangle for an Entity? - collision

Is it possible to define more accurate custom shape collision box rather than rectangle for an Entity?
Please let me know if it is possible and how?

Of course it is possible, and there are multiple possible solutions:
Box2D: is a great physics engine, and available as a plugin for ImpactJS, you can learn how to use this plugin at impactjs.com/documentation/physics-with-box2d
However, Box2D is a bit heavy if you only want to do some custom shape collision.
Custom Entity Collision Check: ImpactJS is a great game engine, it lets you easily extend any of its modules, and for custom entity collision check there are two possible methods:
extend the ig.Game.checkEntities, this allows you to loop through all entities in the game and check their collisions the way you want to.
extend the ig.Entity.check, for lazy people like myself, and only when the custom shape is contained within the entity's rectangle, you can do the entity shape collision check within this function (after entity rectangle collision has already occurred).
ig.Entity.check example:
MyEntity = ig.Entity.extend({
customShape: 'circle',
// custom shape definition...
customShapeProperties: {radius: 0},
check: function(other) {
// custom shape collision check...
if (...) {
this.customCheck(other);
}
},
customCheck: function(body) {}
});
// now if all your entities inherit MyEntity,
// they will have customCheck called only when the custom shape collision occur.

Related

RealityKit fit model entity within field of view

Using RealityKit I’m trying to position a PerspectiveCamera to fit an ModelEntity within its field of view. Specifically I want the entity to fill the frame as much as possible. Does anyone have a function to do this? I've seen an example in a different environment but am not successful in translating it to RealityKit. I need the function to take all three axis into account when determining the camera distance.
Thanks,
Spiff

SceneKit transform/rotate object

I want to create an app using SceneKit with a solid 3D object, whose shape I can change using a given user input. Is it better to do this with predefined animations or to make lots of smaller objects (as nodes) and change their arrangements to mimic a single object changing shape? Many thanks!
Depending on what you mean by 'change shape' you have following options:
If your object is simple (ex: SCNBox, SCNCone, SCNCylinder and alike) and you can change its shape the way you want using its animatable properties (ex: chamfer radius of SCNBox), then animations is simpliest way to go.
If your object is SCNNode with contents loaded from external source and by change its shape you mean scale/rotate/translate, you can also use animations.
If you can create complex object using graph of simple objects with acceptable performance and you can achieve desired shape change with animatable properties then you can also use animations.
If your object is complex (for example, based on some mathematical model) and/or performance is main prioprity for you, then the only way to go with SceneKit is constructing custom SCNGeometries (by filling SCNGeometrySource/SCGeometryElement) from your model.
Since question have tag blender and title mentions rotate, then perhaps (2) is best for you.

how to create event listener to detect if a sprite bounding box is completely in side another sprite bounding box in cocos2dx?

I want an event listener to detect not just a collision, but to detect if a sprite bounding box is completely in side another sprite bounding box, I've used
bool GameScene::onContactBegin(cocos2d::PhysicsContact &contact)
returning false because I don't want any sort of collision physics but got only triggered on first contact.
I want to use physics because its fast and accurate for my purposes.
any ideas ??
One way to achieve this is by storing your colliding sprites in a vector:
std::vector<std::pair<coco2d::Sprite*, cocos2d::Sprite*>> collisionVector;
You can get the 2 colliding sprite objects from contact this way:
auto spriteA = dynamic_cast<Sprite*>(contact.getShapeA()->getBody()->getNode());
auto spriteB = dynamic_cast<Sprite*>(contact.getShapeB()->getBody()->getNode());
Store them in collision vector if neither sprite is null. Do this every time you get a physics contact. Now you can use this in your update() function to check for collision. If there is a collision, you can fire a custom event. You can also use update function to cleanup the list when the collision is over or you deleted a sprite.
To check for collision you need to get the bounding box of each sprite and compare them. You can get bounding box like so:
cocos2d::Rect boundingBox = sprite->getBoundingBox();
Now you can use check both boundingBoxes against each other by testing to see if the 4 corners of the box are within the other box. You can use containsPoint() function of Rect to do this.
Finally, if you found the boundingBoxs are inside one of the other, fire a custom collision event:
void onCollisionInside(Sprite* spriteA, Sprite* spriteB)
{
//do something
}

In Haxe/Flambe, how do I go about rotating or scaling an Entity, so that its children are rotated at scaled proportionally

I'm basically trying to emulate what you see in many other frameworks like Flash, XNA, etc. If I create a hierarchy of nested entities on stage, how do I rotate, scale, or translate a parent entity and have its children rotate, scale, and translate relative to the parent's origin point?
Lets say you have this setup:
Entity (called enemy)
> Sprite
-- Entity (called leg)
> ImageSprite
-- Entity (called arm)
> ImageSprite
-- Entity
> ImageSprite
If you want to rotate the enemy, you should do
enemy.get(Sprite).rotation._ = 35;
Then the whole character should rotate.
If you want to rotate a part of it, use
leg.get(Sprite).rotation.animateTo(35, 0.5, Ease.sineOut);
You can nest entities using addChild, and components (like Sprite) using add().
The displaylist is build using entities that contain Sprites, but not plain nested Sprites like Flash.
I suggest you could take a look at my Flambe guide, some basic concepts (that can be confusing at start) are explained in it
https://github.com/markknol/flambe-guide/wiki/
Have fun, please let know if you have questions.

Unity Mecanim Scripting Dynamic Animation

I have a scene with one fully-rigged model of human body
and I would like to users could make their own animations by transforming the model.
I am talking about an app with time-line and possibility of rotating certain muscles.
Could you please recommend me some way how to do that?
I can imagine storing some information about model state in certain times.. but I do not know how to save it as an animation.
You can't edit animations at runtime. You can create an animation from scratch and use AnimationClip.SetCurve to build up your animation, but you can't access the curves directly at runtime.
However in an editor script you can use the AnimationUtilitys to modify an Animationclip, but of course only in the editor since this is an editor class.
Answer picked from this thread.
I think best possible solution for you is to create many different animations for every body part by your own and let user to choose different combinations of animations (if you are using Animator or Animations). Or you can split model by body parts and let user change transform parameters with iTweens (move from A to B and change angle from C to D). Then u can easily save object's "from" transform and object's "to" transform and use it as animation.

Resources