How to catapult animation in cocos2d.
Iam doing animation of streching stick like rubber, does not get any luck yet,
anyone knows please help.
Thank You.
It's hard to answer your question without more specifics. For instance, are you using one of the physics libraries (Box2D, Chipmunk) or are you rolling your own physics? Are you just trying to model a launched projectile (which is a simple parabola), or do you need to model the physics that actually launches the projectile (which will require a much more detailed model)?
If it's the former, as I said, the animation will just follow the arc of a parabola, but rather than computing the parabolic equation, it's probably easier to animate if you just give the projectile a velocity vector, and apply a gravity vector to it over time.
If it's the latter, I think you need to translate what you want into the physics involved. You mention a catapult, which is about levers, but then you mention a "stretching stick like rubber" which sounds more like spring forces, so the answer to your question is going to depend heavily on what exactly you're trying to achieve.
Related
so I've been trying to see if I can make use of Wheel Colliders for the past several months now. As much as I've managed to figure out more and more things about how to set them up properly, there's some things I've been noticing that seem impossible to avoid:
Even if your friction sideways stiffness is lower, there's a chance that your car will continue to "spin" or "rotate" in the direction you were steering if you JUST hold down your input long enough to get the car beyond just rotating. I've noticed this will happen, whether for example the "SteerHelper" or "TractionControl" functions are doing their work or not. This will put a dent in ensuring smooth turn movement. Now, I don't know if maybe this is just due to realistic car physics (I mean, I can picture the car skidding in scenarios where they lost grip of the road for sure), but it just feels kinda glitchy. Sometimes, even when I'm not turning, the car will start to turn a little to the left or right and then gradually seem to "lean" that way in terms of applied torque to the rigidbody. I've seen many suggestions for trying to stop the rigidbody from doing this. Here is one way I'm trying to work against this:
rb.AddTorque(-rb.angularVelocity * 2);
However, it seems that the car will still "spin" more than intended. What would be ideal is to be able to MAYBE allow the car to turn a little extra after the left or right steer buttons were released (maybe more or less depending on the vehicle), and no more than that to ensure there is maximum control to give the engaged and maybe arcadey game play I've been going for for a long while.
It's been difficult to adapt an ideal friction curve value that would give the most ideal feel of a drift turn, especially a more arcadey one. I'm not trying to go for wide turns that slow you down, I'm trying to go for tight (yet controllable) turns that allow you to preserve most of your speed. I find that especially at higher values of stiffness, as I know many people have observed in other posts, that again, the car will turn back an extremely high amount sometimes (you drift left enough, a force is turning your vehicle way to the right). It's sad, because I've wanted to be able to say I've "mastered this beast" and used it for my purposes, but I don't know if that's really a good practical expectation for anyone. I even worked my own alternate friction curve values that would be used in the controller:
But I guess as some people say, you can't polish something that's broken? Moving to the third point...
I've read so many posts that show how to adjust a vehicle's center of mass, or to add more colliders in different spots to correct it, using scripting to add an offset to the center of mass, etc. So many tips that say, "lower the center of mass, you'll find it" and I give that a try. When the center of mass is too low, my car can get pretty shaky on the terrain (not that it hasn't in the past, but it's often been things I could correct, like the weird initialization of the attachedRigidBody of the wheel colliders themselves in the beginning, etc). High enough, and of course, (even when it's lower sometimes???) the car will just start spinning in the air on either multiple axes or specifically the forward z, when you drive off a ledge or bump into something with a high enough speed. It just seems inevitable.
I've been trying to give my benefits of a doubt. I like to think there's a correct way to use this thing, and that I'm just not familiar enough with Unity3D physics concepts. However, it just seems more and more that I'm investing too much time in a broken component - or, maybe I just never got the best grip of physics.
I was about ready to try just convex mesh colliders around my tires, and just abandon the idea of gripping physics altogether, but I'd love to hear suggestions to either address anything I've mentioned above, or just a more ideal package to move onto. I've glanced at packages like Vehicle Physics Pro, but I do want to be sure I'm getting something that makes sense.
Full disclosure: I'm in the middle of trying to make a game that feels incredibly similar to F-Zero, but with wheels.
Thanks in advance for any thoughts or suggestions you can provide.
(Maybe not an answer per se, but hopefully helpful.)
Note Unity also suggests to possibly give the car a constant downward force via script. It might be telling that such workarounds are officially given, one would think proper physics would, well, properly work without them.
There's some assets you might want to give a try generally:
One is the Unity Asset Store asset called Arcade Car Physics, and it's free. I've tried it and it works (but not sure if it works for your needs). It's using Unity's native Wheel Collider plus extra scripts.
Another is the Arcade Car Physics github project. It has nice plane stabilization and more, and works well. It's not using the native Wheel Collider.
Then there's this asset called Vehicle Physics. Instead of native Wheel Colliders, they've create a fully custom wheel system so that it would be more physically workable. The asset is not free, but they offer a free demo executable where you can drive around different vehicles, and that works quite well. (I haven't yet bought this asset myself.) As a downside, some reviews mention there's some complexity in setting this up (and I suppose future support for this custom Wheel Collider hinges on the company continuing to exist).
Good luck!
Having a bit on an issue, what I want to achieve is a car that is drivable with a D-Pad. I am attempting physics joints on all 4 corners of the "frame" of the car. Then each "wheel" is applied a force to move it forward and backwards. Simple enough I think, can't even get the wheels to stay attached. I weld them to it, but then it won't move.
Second, steering?! How on earth is this accomplished?
Thank you very much, been stressed over getting it to work!
I'm not sure if this is helpful, but here's a link that may push you in the right direction: http://www.emanueleferonato.com/2009/04/06/two-ways-to-make-box2d-cars/. This is an example of what I believe you are looking for, but it's in AS3. However, it's using Box2D physics which is what the CoronaSDK uses. Should be able to translate.
Weld joins don't allow any kind of movement. Pivot joints would be a better choice and more realistic. As for the steering, if this is a top down game, you probably should apply force to the front region of the car and not each wheel as it could do weird things.
I'd like to make game with some windmill in it and want to make wind via b2vec2 gravity vector. I can't find some clear explanation about wind resistance. Is it possible with box2d? May I ask you to point me to necessary functions and documentation please.
What you are trying to do is most likely impossible with box2d, as that would involve the physics being simulated in 3d, while box2d only does 2d physics. If I was you, I would just fake the animation. By having the blades of the windmill in a separate CCSprite than the body of the windmill and then rotating the blades around the z-axis using a CCAnimation that matches the wind speed.
For games
Depending on the game, you may not need to worry about drag force (wind resistance). You could probably get away with pushing objects in the direction the wind is blowing, using an ApplyForce or messing with gravity (like you mentioned in the question).
If you really want to model wind resistance
Looks like linearDampening could be helpful, though unrealistic. True air resistance isn't linear.
You could also do an ApplyForce every frame, opposite the velocity. Unfortunately its been a while since I've taken my mechanics class, so I can't help you with the code, but you could look at this wikipedia article for the formulas
I stole most of this info from this thread:
http://www.box2d.org/forum/viewtopic.php?f=3&t=2718
If you are still having problems
I made some assumptions in my answer. I assumed that you're making rudimentary approximations of things like wind and air resistance. I also assumed you're not truly trying to model a gas pushing a fan, as you probably won't have much luck doing that in 2D, and even if you tried, I can't imagine it adding much to your game.
If you're still confused, try adding some example code to your question, or describe what you are trying to simulate in more detail.
What is the best way for creating Brownian motion with animation in cocos2d for Iphone:
First of all, I am very tempted to vote this question down, but you only have 11 points and I don't want to nuke you lol. You need to post far more information when you ask a question.
Now, I have no idea what you want with this type of animation so I will just have to guess. If you want it for a game (like falling leaves or something) then it is way too expensive in my opinion. It would be better to simulate on a much simpler scale. All I would do in such a situation is set my objects up with AI and have simple situation logic for the object to decide which way to move (what objects are near, wind and other weather, object weight, and chaos/random nature).
Alternatively for a game you might be able to get what you want from Box2D or Chipmunk (depending on what type of actions you desire).
If you want this for some sort of entertainment app (particle systems, auto vector drawing, etc.) then you are in for some complicated math. It is way over my head so if this is the case then I can't really help you.
I'm using Chipmunk 5 for iPhone, with Cocos2D. Upon collision between two specific objects I'd like to run a method which checks the velocity of that collision, if it's over x it runs one set of code, if it's under x it runs another.
Now, I understand the basics but I can't work out the code to run a method on collision detection, and the code to check impact speed.
Any help or pointers would be greatly appreciated.
Cheers.
Check out the addCollisionCallbackBetweenType function in SpaceManager.h That might help with registering collisions.
After that, you can check the v property for the cpBody objects, a cpVect of the velocity. (http://code.google.com/p/chipmunk-physics/source/browse/trunk/include/chipmunk/cpBody.h, not linked, new user.)
I am not experienced with chipmunk, but that's what a little googling turned up.
For Chipmunk 5, assuming that you want to play a sound or apply damage from the collision, I'd recommend calling the cpArbiterTotalImpulse() function from a post-solve callback. You can find more information in the docs here.
http://chipmunk-physics.net/release/Chipmunk-5.x/Chipmunk-5.3.5-Docs/#Callbacks
Also, Chipmunk 5 is fairly old at this point. If it's not a hassle, I'd suggest upgrading to 6.x. Then you could use the cpArbiterTotalKE() function. (If you are near the end of an existing project though, I'd just stick with 5.x.) The kinetic energy is an even better indicator of how "bad" a collision is than the impulse strength.