I'm new to this so pardon me if I'm not quite giving enough detail about something, but... I'm trying to make a sort of curving stream, like water coming out of a fountain, only with more distinct particles than a continuous stream. I admit, I have no idea where to start as the documentation on threejs.org seems incomplete. Basically I want to have particles shoot out of one point and curve down into another. I figure I can use CurvePath or some such thing, as (as far as I know) I can specify a curve with a ridiculous number of points (is there a way to do a curve perhaps by specifying start and end points, rotation, and distance from the center to the apex?) and then I assume there's a straightforwardish way to make something move along a Path.
If you have a limited amount of objects to want to move along a path, the way I would do it is
as you said, create a Curve (look at the Curve subclasses to find one that suits you)
use something like Tween.js or jQuery to execute an easing function from 0 to 1
pass the easing value to Curve.getPoint(distance) to get a position along the path
add some randomness on this point to make a stream effect
Or, using a kind-of-physical particle engine, like http://stemkoski.github.io/Three.js/Particle-Engine.html
Related
I am making a relatively simple isometric map using SpriteKit. I've tried both using the editor as well as creating it through code, and each time, it seems to have some "weighting" between the various tiles even though they should overlap gracefully given that I'm just setting the styling of a tile.
Here is an example of me using the tiles from https://kenney.nl. The green is just a standard grass patch and the road is the same exact size as it.
When I create this map in the XCode UI or if i iterate through in code and paint them, this continues to occur.
However, if I was to do something like flip the tiles around and paint it all with roads with grass in the middle, it then seems to sort whichever tile there are "more of" like in this example:
If i go and make more of one tile group over another, it seems to overpower it.
So my question is, how can I keep them from using this behavior? I've tried different tilemaps together, nested them inside of eachother etc... But at the end of the day, I cant get different tiles to exist at the same "plane". I've tried with code, the UI, etc. I'd like to use the SKTileMap if possible to use the downstream features as opposed to doing all of the math myself, like in the approach in this article (http://bigspritegames.com/isometric-tile-based-game-part-1/)
The SKEmitterNode in SpriteKit lets you change particle properties, but it's not clear how you change properties for specific particles.
For instance, if we want particles to radiate in a circle shape, it seems we need to dictate the angle and speed for each particle -- not specify values for particles as a group.
Is this possible?
Put another way, is it possible to use the SKEmitterNode to create animations like the one from this video at the 0:22 mark: https://www.youtube.com/watch?v=wYy2G0lVTAM
you can do:
The image is a little star.
setting:
You have no control over individual particles, you can only determine what they are like when they are born. (think of it like a test-tube baby, you can specify what genes you want the baby to have, but after that, the baby will grow however it feels like)
At some point apple may get SKActions working on the particles so that you can do this kind of stuff, but I wouldn't hold my breath on it working anytime soon, they seem to have no care in the SpriteKit platform, just introducing new broken things to get people excited. ( I am cringing on how buggy ARKit will be)
I read the example in the apple documentation (Scene Kit Vehicle) and they use SCNPhysicsVehicle on the vehicle. SCNPhysicsVehicle allows to set speed, brake and everything. I want to be able to control a SCNNode (containing a SCNSphere). What is the way to do that by physic?
Use SCNPhysicsVehicle only when you want an element in your scene to behave like a wheeled vehicle — to control it in terms of engine speed, braking, and steering, and to display it with wheels that rotate as it moves and pivot as it steers.
For simpler physics-based control of an element in your scene, create an SNCPhysicsBody and attach it to the node for which you want physical behaviors. Then, to set it in motion, apply forces or impulses to it, directly set its velocity, set it up to collide with other bodies, or just let it fall due to the scene's gravity. There's far too many things to do with physics to fit in one answer — read the SCNPhysicsBody Class Reference to see them all.
If you're looking specifically for joystick/tilt control, even then there are multiple ways to go, depending on what kind of gameplay "feel" you're looking for. But there are some common themes:
Since you want continuous control, you probably want to poll for input in renderer:didUpdateAtTime:or one of the other render-loop methods.
Tilt and joysticks provide variable input, so you probably want variable control. Whatever you do to the physics body should scale with the accelerometer input or joystick axis value.
One thing you could do is apply a force on every frame based on the joystick direction; e.g. in your update method:
GCControllerAxisInput *joystickX = controllers[0].extendedGamepad.xAxis;
[sphereNode.physicsBody applyForce:SCNVector3(xAxis.value * SCALE_FACTOR, 0, 0) impulse:NO];
With this option, holding the joystick one direction or the other is like firing thrusters: your sphere will move faster and faster the longer (and stronger) you hold the joystick in a particular direction. And you'll have to hold the joystick just as much in the opposite direction to apply enough opposing force to stop that crazy thing.
Another way to do it would be to set velocity directly:
sphereNode.physicsBody.velocity = SCNVector3(xAxis.value * SCALE_FACTOR, 0, 0);
With this option, the sphere holds still when you're not pushing the stick, and it moves faster the farther you push the stick, up to the maximum speed of SCALE_FACTOR.
(In both examples, SCALE_FACTOR is something that translates the -1 to 1 range of the joystick into units meaningful to your game.)
There are loads of other options — for example, you could do your own math to derive a delta between the joystick position and the current direction/velocity — experiment with some to find out what best fits the gameplay you're looking for.
I'm currently trying to find a neat way of storing separate "branches" in a binary image. This little animation explains it:
As I go along the branches I need to collect the pixel indices that makes up a single-pixel wide branch. When I hit a junction point it should split up and store the new branches.
One way of going about it is maybe to create a 3x3 subregion, find out if there are white pixels inside it, move it accordingly, create a junction point if there is more than two. Always store the previous subregion so one can use it for making sure that we don't move to regions we already scanned.
It's a bit tricky to figure out how I would go about it though.
I basically need to reorder the pixels based on a "line/curve" hierarchy. Another part of the application will then redraw the figures, which internally works by creating lines between points hence the need to have them "ordered".
I don't know if you could apply it in your case but you should take a look at cv::findContour.
you will get a vector of points ordered.
http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/find_contours/find_contours.html
I've been suffering from an issue regarding the implementation of orienting characters in a game I'm implementing using Ogre3D and Bullet physics.
What I have: A Direction Vector that the character is moving in, along with its current orientation.
What I need: To set the orientation of the character to face the way it is moving.
I have a snippet of code that sort of does what I want:
btTransform src = body->getCenterOfMassTransform();
btVector3 up = BtOgre::Convert::toBullet(Ogre::Vector3::UNIT_X);
btVector3 normDirection = mDirection.normalized();
btScalar angle = acos(up.dot(normDirection));
btVector3 axis = up.cross(normDirection);
src.setRotation(btQuaternion(axis, angle));
body->setCenterOfMassTransform(src);
Where 'body' is the rigidbody I'm trying to orient.
This snippet has a couple of problems however:
1) When changing direction, it tends to 'jitter' i.e. it rapidly faces one way, then the opposite for a second or so before correcting itself to the orientation it is supposed to be at.
2) Most times that the code is run I get an assertion error from Bullet's btQuaternion on
assert(d != btScalar(0.0));
Can anyone help?
Thanks!
I think you shouldn't use functions like 'acos' for such things, as it may cause some inconsistencies in border-cases as the 180 vs 0 rotation mentioned above. You can also get high numerical error for such data.
The second thing is that - in general - you should avoid setting explicit position and rotation in physics engines, but rather apply forces and torques to make your body moving as you want. Your current approach may work perfectly now, but when you add another object and force you character to occupy the same space, your simulation will explode. And at this stage it's very hard to fix it, so it's better to do it right from start :) .
I know that finding correct force/torque can be tricky but it's the best way to make your simulation consistent.