how to track the path of ball flowing motion in cocos 2d
For example in angry bird game video the bird flowing motion. they display the path. likewise i want
You could accomplish this by using an NSTimer or CADisplayLink to repeatedly use the coordinates of the thing in its path of movement (e.g. 6 times a second) and display a small dot at that coordinate. The timer would begin, for example in angry birds, when the bird is first launched, and then stopped when the bird hits something.
bird is launched (timer is created and method is called 6 times a second)
Every 1/6 of second a dot is draw at the bird coordinate at that moment
The timer is stopped when the bird hits something so no more dots are drawn
You could use the CCMotionStreak Cocos2d class which utilizes CCRibbon. Check out Riq's MotionStreak test on github (onEnter:)
Related
I have data for an actors movement which is being read in from a file at the start of the game. The data that gets read in contains Vector positions where the Actor should move to next. I currently have the Actor moving from Position to Position no problem... until I start to add animation to a Skeletal Mesh attached to the Actor.
My problem: How can I found out the velocity to work out which animation to play idle, walk, jog and running? It currently doesnt have a velocity as i am lerping the position:
SetActorLocation(FMath::Lerp(GetActorLocation(), newPos, 0.01));
Any thoughts on how to set the right animation based on distance travel and speed?
Should I move my Actors movement to Character so I can use AddMovementInput to get velocity. Then, If i go down that route, how to I say:
Move this character from my current position, to my next position in X amount of time giving the character the correct velocity to use in the animation selection.
Can you normalize the difference between the two vector lengths (GetWorldLocation) and use the abs(floating point) result as the X variable to put into 1D Blend Space to do idle, walk, jog, run in your Animation BP? Also be sure to account for an "acceptance radius" or else once it gets to location it won't quite get it and keep turning quickly.
Not sure why you're Lerping from Vector to Vector. I would've personally used (MoveToActor or MoveToLocation):
AMyPawn->MoveToActor(AMyActor, 90.f,true,true,false,0,true);
So much cleaner! Also MoveToLocation, using BT/BB.
I try to make 2D game with C++ using SFML. I have drawn sprite and now I want to make that sprite moving automatically to random direction and when it hit wall then it bounce away and change direction. I don't know how to do auto moving sprite what bounce from wall... So please help me.
sf::Sprite has a member function setPosition (float x, float y) that you can use to set the position of the sprite before it's drawn. By moving the sprite to a new position each frame you create the impression of movement, much like a cartoon. By comparing the position of the sprite with the position of other elements in your scene, like the walls, you can calculate when 2 objects hit and take appropriate action. Typically it works like this:
Reset a clock at the beginning of a new frame, you can use sf::Clock or C++'s chrono for example.
Update the position of all elements in the scene that should be moving with something like: ObjectSpeed * Previous frame time
Draw the frame
Save time elapsed for calculating the next frame
Loop
I am making a 2D game and I have created two circles, one named player and one named enemy. The circles are drawn by calling a drawPlayerCircle and drawEnemyCircle function, both which are called in my display() function. At the moment my project isn't Object Orientated which you can already probably tell. My collision works for both circles as I have calculated penetration vectors and normalised vectors etc... However my question is, expanding this game further by having 10-20 enemies in the game, how can I work out the collision to every single enemy quickly rather than calculating manually the penetration and normalised vectors between my player and every enemy in the game which is obviously very inefficient. I'm guessing splitting my player and enemy entities into their own class but I'm still struggling to visualise how the collision will work.
Any help will be greatly appreciated! :)
Collision between two circles is very quick to test. Just check if the distance between the circle centre points is less than the sum of the two radii.
I would just start by comparing the player against every other enemy. Doing 20 comparisons is not going to tax any computer from the last 10 years. I'm a big believer in just writing the code that you need right now and not complicating things, especially when you are just starting out.
However if you end up having millions of circles and you've profiled your code and found that testing all circles is slow, there are quite a few options. The simplest might be to have a grid over the play area.
Each grid cell covers a fixed amount of space over the play area and stores a list of circles. Whenever a circle moves calculate which grid cell it should be in. Remove it from the grid cell that it is currently in, and add it to the grid cell that it should be in. Then you can compare only the circles that overlap the player's grid cell.
Space partitioning. Specifically, if you're in 2D, you can use a quadtree to speed up collision detection.
I have seen this before, and making my research i've discovered that if you create allot of circles objects in box2d, then apply a color, then blur it and at the end sharp it a little bit ( same stile like "Where is my water" game created by disney ).
But of course in a game like limbo, with a huge world this is extremely expensive.
Since i have seen this in a few games over the internet i still trying to understand how can i build this with box2d ? ( the games over the internet where/are created with in flash, and i want to do it in cocos2d for the iOS platform )
a few examples about how the water works, for those that didn't played the Limbo game:
1.A box will flow on the water, the box will enter in the water only half of it and half of the box will will remain above the water. If an object (like: the player ) will falls above it the box will have the end of the titanic, it will sink.
2.A rock will sink.
3.The player, well i guess here will be different choices.
4.A boat, for the bout i know a bool should do the trick BOOL canSink; but again how should i make that water effect ? balancing the object on it, an bouncing if the object falls in the water, and for sinking a slower velocity ?
It may look like allot of questions,but at the end is only the " How to create the water effect in box2d?"
I guess you're looking for buoyancy effects, here you have a couple of interesting resources.-
http://www.iforce2d.net/b2dtut/buoyancy
http://personal.boristhebrave.com/project/b2buoyancycontroller/demo
As for the water waves effect, you can take a look at.-
http://www.sideroller.com/wck/?f=6
http://www.cocos2d-iphone.org/forum/topic/25494
Hope it helps.
Im using Level Helper and SpriteHelper to create my sprites, images, levels and more importantly animations and physics.
Note, by physics i mean the debugdraw you can see on the simulator that is used for collision detection.
I created a swimmer and added physics to this. Done the code so the physics follows the swimmer around the pool as they move. I have now come to animate the swimmer, make the legs kick etc. Now when i load my game and only the first sprite of the animation is the outline for the physics. So i can see the legs kicking on the swimmer but the debugdraw mesh of the physics doesn't animate as well. Now this is not really a problem until for example my swimmer loses their legs (weird game i know). I change the animation to now a swimmer with no legs but again the physics mesh still shows the legs. So any collisions with stuff still happens where the legs were but they shouldnt. This make sense?
Is there a way to update the physics on the new animation or do i need to remove my whole swimmer and draw a new one?
Any help at all would be great. Thanks
This makes sense, since your sprite uses the same box2d mesh in both states. If you want to have a different collision behavior after altering your Sprite, you should assign another (smaller) mesh body.
Note that even in cocos2d side, your sprite still has the same container box with the new animation.
In order to keep using the SpriteHelper functionality you might want to create 2 different sprite-body sets: one with the full body, then after the "accident" replace it with the legless sprite.
Now, gameplay-wise, my opinion is that there shouldn't be any collision for the legs anyway. since they are moving, players will not find it weird to have them not colliding. You could use a mesh body with no legs and use it for both sprites. Except if you want to have different collisions as a gameplay feature (Like giving the player the choice to cut his legs in order to fit in a smaller cave etc)