I'm new at games development and now stalled at one problem.
Trying to make tower defence type game, For now i have made "tower" with some functions, and where is problem with firing bullets.
Idea: touch somewhere on screen and bullet fire that direction. (bullet starting pos in middle of screen, speed must be a constant)
Maybe somebody knows how to calc that direction which bullet should fire.
I think, should calc angle or something to get that direction...
i.e.
this.mPhysicsHandler.setVelocity(angle*SPEED, angle*SPEED);
Thanks.
It depends a little bit if it's 2D or 3D but the idea is basically the same.
I would start by making a Vector class which has to variables, x and y. I would then add a few method for adding and subtracting Vectors. What you would have to do then would be to subtract from the touchPosition Vector the firingPosition Vector which would give you the direction Vector towards which you have to shoot.
If you need more help with this just comment.
Related
Could someone explain me how convex path is calculated? I need to draw some cubic and additionally some lines but then path is shown as non convex. However when I leave only lines or just cubic it is then convex. The problem is that I need some non regular shaped background and need Convex path for shadow outline but can't get how I could connect drawing cubic with some lines to make convex path if it is even possible
A path is convex if it has a single contour, and only ever curves in a single direction.
Convex means it keeps bending / rotating in one direction, and one direction only. You really have to make sure that all your angles and curves add up. If your curve connects to a line it has to have the same angle or be "more convex", I hope the following 2 images will clear this up.
The picture below is not convex. That's also likely your problem. The line connects to a curve, but the curve has a different angle than the line and it will change the direction where it connects. See where the line goes down but instead of continuing the downwards-motion it suddenly goes up again. Instead of keeping one direction it will change for a moment where line and curve meet.
The above Image is exaggerated for clarity, but even small errors in the connection between the line and curve will trigger an error.
The next line connects to a curve with a steeper angle. This is convex and won't be a problem. See how the whole contour keeps a single motion in one direction, depending in which direction you follow it it keeps turning left/right.
I answered because I was facing a similar issue recently and I feel your pain. I recommend pen and paper to double and triple check the math and to use a small epsilon value to account for rounding errors etc... You really have to nail the math, because if your line and curve connection is just off by very little it will throw that exception.
Sorry for my bad paint skills
My android app is to use GPS to help layout a sports field, like a football field. You enter the dimensions of the rectangle, tell the app which corner you want to start with and which corner you want to go to next. The app will tell you when you have walked far enough. Once you have laid down the first two corners, the app will then direct you to the next corner (logic in the app make sure you only select corners that make sense). This is where the trouble comes in. You may be going clockwise or counter-clockwise. I need to know which way to turn for the third point. I know how far I need to go, and I know how to figure out a right angle, but I don't know how to figure out if I went the right way.
I was thinking about forcing the user to go one way or the other, but the problem is that often times a field is laid out with an obstacle on one side (a street, cornfield, fence, whatever). In that case, you will usually want to start at the obstacle and work your way out.
So, to put the question one other way, given two points, A & B (lat & long), how can I calculate the third point that is at right angle to the segment AB and in the right direction? For example, if the user says they want to start with corner 2 and then corner 8, how do I calculate the gps coordinates for corner 7?
I realize that this is possibly/probably more of a geometry question than an android question, but it may be that there is a specific android solution.
I agree with you that this is not an Android question, but a geometry question. Nothing by default in Android to program this I'm afraid.
Great link that I use to remember how I have to calculate distances on the survace of the earth is http://www.movable-type.co.uk/scripts/latlong.html.
Calculate bearing between given corners (for your example, between 2 and 8)
Calculate bearing for next corner you want to know (bearing between 2 and 8 + 90 degrees)
Find destination point given distance and bearing from start point (start point is 8, use bearing calculated at step 2 and I assume you know the dimensions of the field)
I'm looking to implement movement from character to character on a tiled board. I have a 7x7 board set up with each tile representing a character. The player is able to move in up to the 8 directions around the tile (providing proper game logic). I am able to accurately get the character at a given tile based on a onTouch() Action_Down.
For a more elegant solution though I am looking to press and drag to move between tiles/create words. I'm not exactly sure where I should start with this.
I can figure out all the logic for appropriate moves etc. But my question is how to recognize a left movement from 1 position to another as selecting tiles?
My current idea is to have hard boarders but that will not work for diagonal. Then my next idea is to have diagonal boarders instead so like:
This solution seems a little complex though. Is there any easier way to accomplish this?
I am developing a mobile game for iOS and Android with Starling. I am very new to this framework. I need to add a sprite to the screen and then have the initial point on the screen that was touched be anchor point 1 and then the user will drag there finger which will adjust the second anchor point until they release their finger from the screen. Imagine several nodes that need connected by a line and you can picture what I am trying to do. The problem is that I can change the pivot to be at the beginning of the line but I dont know how to make the other anchor point work. I also cannot use anything other than a sprite as the line is animated by a sprite sheet. Any help that can be provided is greatly helpful, I have been thinking about this for a while now and can't seem to figure it out. Code is helpful and preferred but just giving me an outline of the concept would help as I can probably figure out code. Thanks!
I don't know actionscript but I'm sure if it is for android the touch event has 3 phases (generally): touch down, touch move, touch up.
You say you only have a sprite so define some variables:
initX, initY, finalX and finalY. All floats (or ints if you cast them). And a couple of booleans: set1 and set2 all false
On touch down you ask if set1== false if so, set initX=eventX and initY=eventY (eventX and eventY would be here the X and Y of the touch event). Then set set1=true
On touch move you do the same as above, with set2. if set2==false, set finalX=eventX and finalY=eventY, then set2=true.
and you draw your sprite from (initX,initY) to (finalX,finalY) or if you're using width/height then finalX-initX for the width, finalY-initY for height.
I hope this helped. I didn't even know starling existed but since it's actionscript it must be pretty close to java in its syntax
This is my first post on this forum and I'm very new in programming. I want to build an application where I can see exactly where some gps-values are on my phone. I know a lot of applications, like junaio, mixare and others, but they only show the direction to the objects and they are not very accurate (they don't have the goal to project it on the exact position on screen) - so I want to build it myself. I program in android, but I think it would be the same on iPhone.
I followed the steps suggested from dabhaid :
There are three steps.
1) Determine your position and orientation using sensors.
2) Convert from GPS coordinate space to a planar coordinate space by determining the relative position and bearing of known GPS coordinates using e.g great circle distance and bearing. (your devices stays at the origin of the coordinate space with this scheme)
3) Do a perspective projection http://en.wikipedia.org/wiki/3D_projection#Perspective_projection to figure out where on the plane that is your display (ok, your camera sensor) the objects should appear, so you can augment them.
Step 1: easy, I have the gps-position and all orientations from my mobile device (x,y,z). For further refinements, I can use some algorithm to smooth this values (average, low filter, whatever).
Step 2: I don't know, what is exactly meant by planar coordinate space. I have some different approaches to convert my gps coordinate space. One of them is ECEF (earth centered), where 0,0,0 is the center of the earth. Somehow, this doesn't look good to me, because every little change of ONE axis, results in changes of the other two axis. So if I change the altitude, all of the 3 axis will change. I don't know if I can follow step 3 with this coordinate system.
In step 2 is mentioned: using haversine - this would give me the distance to the point, but I don't get x,y,z from it. Do I have to calculate x,y by using trigometry (bearing (alpha) + distance (hypotenuse)) ?
Step 3: This method looks really cool! If I have my coordinate space from Step 2, I can calculate d_x,d_y,d_z by using the formula on wikipedia. But after this step, I'm not finished yet because i just have the coordinates and for projecting it on my screen, I only need two coordinates? The text from wikipedia is continued by calculating b_x,b_y They use e_x,e_y,e_z which is the viewer's position relative to the display surface -> How can I get these values from my mobile device? (android/ios). Another approach, which is suggested from wikipedia is: Calculating b_x,b_y by by using the formula mentioned on wikipedia. In this formula they use s_x,s_y, which is the screen size and r_x,r_y which is the recording surface size. Again, how can I get the recording surface from my mobile device?
I can't find anything for it on the internet. It seems that nobody on android/ios has ever implemented a perspective projection before...
Thank you very much for all of your answeres! Also, links to useful sites would help!
I think you can find many answers in this other thread: Transform GPS-Points to Screen-Points with Perspective Projection in Android.
Hope it helped, bye!
Here's a simple solution I did on this issue.
A: Mapping GPS locations on the camera preview in Android
Hope it helped. :D