Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I'm trying to make a game where nodes fall from the top of the screen to the bottom, which I've done by using gravity. Now I want to move some nodes from the left side to the right.
I was wondering if I could change the gravity pull on different nodes instead of them falling down the screen the gravity could pull selected nodes left to right.
I know I can do this by using a NSTimer and a function but wondering if I could do this with gravity.
I have tried googling the answer but I can't find the answer to applying two gravity pulls.
I don't think you can have 2 distinct gravity forces into the same physics world.
However if you want some node to "fall" to right you could
Apply another acceleration (same as gravity but opposite direction) to that specific body (this will cancel the gravity pull)
Apply one more acceleration versus right to the specific node.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm working on a little project in which I would like two circles to connect through a gooey effect. I've searched the web quiet a lot and came across some examples in the form of a tabbar, or sidebar menu, but that's all fixed and not what I'm looking for.
What I basically want is the following. So there is a circle and if I drag it closely to another circle it snaps together, also known as the gooey effect.
A code sample would be the best, but a direction / approach of how to do this will help me out as well.
Interesting problem.
Off the top of my head, here is how I might handle it:
Calculate the points of intersection of the 2 circles (I found this link for that: Circle-circle intersection points)
Calculate the arc ranges of the intersecting parts of each circle.
Widen those arc ranges by a few degrees. Define the arcs for the remaining parts of each circle (The parts that would be drawn "non-gooey")
Using trig and Catmull-Rom splines, create a closed path for the outer "non-gooey" parts of each circle.
The Catmull-Rom algorithm should fill in the gaps between the 2 part-circles using smooth curves that look a lot like the "Gooey" circles you show.
I have a project on github that includes Swift code for creating Catmull-Rom splines from a series of points: Trochoid demo
That project creates open curves, not closed paths. The technique for creating smoothed closed paths using Catmull-Rom Splines is a little different. I have another Github project called RandomBlobs (Written in Objective-C) that creates smoothed closed paths. You should be able to work out how to change the Swift code to create closed paths from the Objective-C code. It's been long enough since I wrote the RandomBlobs code that I don't remember exactly what I did.
I'm not sure if the approach I describe above would be fast enough to draw in real time, but I bet it would. That TrochoidDemo project is doing a lot of trig for each animation frame, and it's animation is pretty smooth. If your project isn't smooth enough you might need to do some optimization.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
What I'm trying to do seems very simple, yet I'm struggling to make it work. I'm creating a simple SpriteKit game, similar to FlappyBird. The main character stays vertically stationary while the user controls its horizontal motion. That part is no problem. At the same time, other game elements should be moving vertically at a constant speed. I need to detect contact, but do not need to react with physics to the contact (the moving elements either disappear on contact, or the contact causes game to end).
I've tried using physicsBody.velocity, but the results are erratic. Conceptually, this is my desired approach because I want to control the velocity, speeding or slowing as the game progresses.
I've also tried using Actions, and this works ok but it's challenging to create constant motion, and it's difficult to imagine how to speed and slow the motion with Actions. My best results are with SKAction.sequence, but have difficulty coordinating multiple elements to move in sync.
Any clues would be most appreciated.
You can create the host node – world: SKNode to control all the moving objects – just add them as childs. And use that node to rule the world – set world.speed = 0.0 to stop all SKActions, world.speed = 2.0 to move them twice as faster
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
for university I'm working on a project in which I have to teach a robot(Nao-robot) play nine men's morris. Unfortunately I'm fairly new to the area of robotics and I need some tips how to solve some problems. Currently I'm working on the localization/orientation of the robot and I'm wondering which approach of localization would fit best in my project.
A short explanation of the project:
The robot has a fixed starting position and has to walk around on a boardwhich has a size of about 3x3 meter ( I will post a picture of the board when i reach 10 reputation). There are no obstacles on the field except the game tokens and the game lines are marked yellow on the board. For orientation I use the two camera devices the robot has.
I found some approaches like
Monte Carlo Localization
SLAM (Simultaneous Localization and Mapping)
but these approaches seem to be quite complex for a beginner like me and I would really appreciate if some has some good ideas what would be a simpler way to solve this problem. Functionality has for me a far higher priority than performance.
I have vague knowledge about the nine men's morris game as such, but I will try to give you my simpler idea.
First thing first, you need to have a map of your board. This should be easy in your case, cause your environment is static. There are few technique to do this mapping from your board. For your case I would suggest to have a metric map, which is an occupancy grid. Assign coordinates to each cell in the grid. This will be helpful in robot navigation.
As you have mentioned, your robot starts from a fixed position. On start up, initialize your robot with this reference location and orientation (with respect to X-Y axes of the grid, may be you don't need the cameras, I am not sure!!). By initialization I mean, mark your position on the grid.
Use Dead Reckoning for localization and keep updating position and orientation of your robot as it move through the board. I would hope that your robot get some feedback from the servos, like number of rotations and so forth. Do that math and update the position coordinates of your robot as it move into different cell in the grid.
You can use A-Star algorithm to find a path for your robot. You need to do the path planning before you want to navigate. You also have to mark those game tokens on the grid, to avoid collisions in planning the path.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
In the Image above (Top Image), suppose the black boundary is the phone.
What i was trying to achieve is to randomly generate the red path from the top of the screen and at the same time the red line (path) moves downwards.
Notice how the red path is random and does not have a uniform shape.
My question is how do i achieve this?
I know this has something to do with the random function.
But then generating the random path has been my main obstacle since 8 hours.
I could not generate a shape at every interval of the timer with a specific x coordinate and y coordinate but then as you can see in the next image, how would i generate the line at an angle (rotated)
Have tried hard to search everywhere on the internet but failed.
I always keep stackoverflow my last destination after I fail to achieve any functionality after numerous hours.
Would really appreciate if anyone could help me out with this.
It looks like you could achieve the effect you wish by starting at the top center, and repeatedly choosing 2 random numbers: how far down to go, and how far horizontally to go (positive or negative), until you got to the bottom of the screen. You'd have to be careful not to go off either edge, or you could instead choose a random x-coordinate each step.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to draw a words grid that user can select the wrods, like the image below
I think the best way is to use a UICollectionView element for draw a grid but how can I handle touch events and mark selected letters?
There is no one answer to your question. You could use individual UIButtons for each letter or set up your own touch coordinate tracking system corresponding to letters or do something completely different. It boils down to what you feel comfortable working with and your experience level. To get the ball rolling, I would suggest you take a look at this Ray Wenderlich tutorial which shows how to create a letter word game by dragging letter tiles. The tech in this tutorial will definitely help you with your project.
Updated:
If you go the button route, you can create them programmatically and pretty much do anything you want. Change their title (in your case) letter, show or hide them, track various kind of touches, and so on. For the letters and tracking touches, there are probably a number of methods of doing this. Try putting your letters on a subview while keeping track of their center coordinates. Then add a new subview over your letters to track the user's touches.
You will have to read and understand the UIGestureRecognizer Class.
Here is an example of how to get a user's screen coordinates from a touch.