Java-Gaming.org Hi !
 Featured games (83) games approved by the League of Dukes Games in Showcase (581) Games in Android Showcase (162) games submitted by our members Games in WIP (632) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
 Show Posts Pages: [1]
1  Game Development / Newbie & Debugging Questions / Re: Rotate Towards Point on: 2013-01-23 21:01:54
Solution

I've finally reached a perfect solution, although I can't say this code is as efficient as can be. The real problem ended up the different way rotations were being stored. For the entities rotation, it run counterclockwise 0-360. The result of atan2 gave me something running clockwise and -180-180. The key turned out to be converting to counterclockwise 0-360, after which it was a trivial solution, although code posted earlier on here helped out, particulary in ensuring there isn't jerky movement when the entity is pointing towards the ship out by only a fraction of a degree.

I'm not sure if this solution would apply to anyone else's code, but hopefully it could be of help to somebody. Either way, there is plenty of reading material on this post, and I'd like to thank everybody who contributed and helped solve my issue!

 1  2  3  4  5  6  7  8  9  10  11  12 `playerAngle = (float) (Math.toDegrees((MathUtils.atan2(player.y-y, player.x-x)))+270)%360;shipRotation = Math.abs(rotation%360);turnSpeed = 2;angle = playerAngle-shipRotation;            if(Math.abs(angle)
 2 Game Development / Newbie & Debugging Questions / Re: Rotate Towards Point on: 2013-01-23 20:16:50 I'm really confused, sorry, but this is maths all beyond my ability. Could anybody clarify how to actually practically implement this, ideally with  minimal advanced vector manipulation (advanced for me)! Thanks
 3 Game Development / Newbie & Debugging Questions / Re: Rotate Towards Point on: 2013-01-21 21:48:03 Quote from: matheus23 on 2013-01-21 20:23:12Just an offtopic question: Why the heck is it (y, x) and not the usual (x, y)?That's just the order the atan2 function in java's math library wants them.
4  Game Development / Newbie & Debugging Questions / Re: Rotate Towards Point on: 2013-01-21 19:59:52
 1 `playerAngle = (float) Math.toDegrees(Math.atan2(player.x-x, player.y - y));`

This line is wrong. It should be

 1 `playerAngle = (float) Math.toDegrees(Math.atan2(player.y-y, player.x - x));`

Oh yeah, cheers.

I'm still confused on how to get this fully working though. Merely using playerAngle won't account for the entities current rotation, it'll only give the angle between two points. The entity will just spin infinitely as playerAngle will never change so long as it is static, despite it rotating. How do I factor in it's rotation?

Thanks
5  Game Development / Newbie & Debugging Questions / Re: Rotate Towards Point on: 2013-01-21 19:48:54
Ok, so currently I am at this:

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15 `playerAngle = (float) Math.toDegrees(Math.atan2(player.x-x, player.y - y));turnSpeed = 2;                  if(Math.abs(playerAngle) < turnSpeed)   {      rotation = playerAngle;   }   else if(playerAngle > 0)   {      rotation -= turnSpeed;   }   else   {      rotation += turnSpeed;   }`

At the moment it seems I am only accounting for the angle between two co-ordinates, and not the current rotation of the entity. It's integrating that part that I'm finding most difficult.
6  Game Development / Newbie & Debugging Questions / Re: Rotate Towards Point on: 2013-01-21 19:40:54
 1 `PlayerAngle = (float) Math.toDegrees(Math.atan2(player.x-x, player.y - y));`

This will give me the angle between -180 and 180, I'm not sure what the need for the dot product is?

Edit:
Sorry, you said 'or', my bad!
7  Game Development / Newbie & Debugging Questions / Re: Rotate Towards Point on: 2013-01-21 19:31:25
Thanks for the help, I'm relatively new to Vector Maths, is this code looking somewhat right?

Written in the update method of an entity, trying to point towards the player.

 1  2  3  4 `Vector2 p1 = new Vector2(x/Math.abs(x),y/Math.abs(y));Vector2 p2 = new Vector2(player.x/Math.abs(player.x),player.y/Math.abs(player.y));         float angle = (float) Math.acos(Math.toRadians(p1.dot(p2)));`
 8 Game Development / Newbie & Debugging Questions / Rotate Towards Point on: 2013-01-21 18:44:45 Hi,I expect a very simple answer, but beyond me. I've done some searching but can't find anything.I want to rotate a sprite at a constant rate a tick so it will try to face another sprite.I can calculate the angle between them, it's dealing with the rotation increment/decrement when the angle crosses the 360 degrees mark to 0 degrees, messes up my code and I just can't think through it.Many thanks for any help!
 9 Game Development / Newbie & Debugging Questions / Re: Line Intersecting Polygon Not Working on: 2013-01-13 20:41:19 The laser is line not a ray, it has a direction, a start point and a length, it's a finite distance.The geometry consists of line segments with start and end points (A list of vertices in order, from which I can deduce the points of the segments).Would this affect your code in any way? I'm not particularly experienced in vector mathematics. Thanks
10  Game Development / Newbie & Debugging Questions / Line Intersecting Polygon Not Working on: 2013-01-13 20:11:47
Hi There,

I'm writing a small space game using libgdx, the ship fires a laser, and I need to calculate when (if ever) it intersects a poly (asteroids). This is so I can stop the laser passing through the objects, and actually collide with them. My code seems to work some of the time, and completely fails at other points. I can't figure out what causes it to fail, I'm pretty sure it's not my poly definitions that are wrong, as sometimes it will work on an edge, other times not, there is no consistency.

I have checked the trace of my ray (strictly speaking a line) and it is spot on, so it's not that. Here is the code, I'll try to explain what I've done after.

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53 `//Beam Collisions//If the beam isn't being fired, returnif(!active) return;   //Storing all the points to be checked on the beam, I've checked the all seem accurate, and have draw a line between them and they match the laser.   List beamPoints = new ArrayList();//Step allows me to reduce the number points I test when it finally worksint step = 1;for(int n=0;n verts = new ArrayList();   for(Vector2 v : e.getGeometry()){                      //Determining the x and y of the vertice to store. e.x is the asteroids world coords, I subtract the half the imageWidth because it's position is stored as the centre of the graphic.                //I then add the relative x and y of the vertex.                //I've turned off rotation for the asteroids, so that's not a problem.      float nx = (e.x-e.imageWidth/2)+v.x;      float ny = (e.y-e.imageHeight/2)+v.y;            verts.add(new Vector2(nx,ny));         }           //Testing each of the points on the beam to see if there are in the poly.   for(int j=0;j

I should also point out from the following images that by the laser I mean the bright core, I haven't bothered messing around with it's glow, that's not faulty, I just haven't done it yet.

I hope this is enough code to go by, if there is anything else I can provide please ask; I'm greatful for whatever help you can give.

Cheers guys,

Daniel
 Pages: [1]
 MrMapcom (15 views) 2015-05-23 20:26:16 MrMapcom (20 views) 2015-05-23 20:23:34 Waterwolf (29 views) 2015-05-20 15:01:45 chrislo27 (35 views) 2015-05-20 03:42:21 BurntPizza (70 views) 2015-05-10 15:53:18 FrozenShade (56 views) 2015-05-07 09:11:21 TheLopais (218 views) 2015-05-06 13:36:48 TheLopais (202 views) 2015-05-06 13:35:14 TheLopais (207 views) 2015-05-06 13:33:39 TheLopais (226 views) 2015-05-06 13:32:48
 Spasi 32x BurntPizza 16x Riven 15x ra4king 12x theagentd 11x DavidBVal 11x Husk 11x EgonOlsen 11x KevinWorkman 9x princec 8x scanevaro 8x opiop65 7x Slyth2727 6x revers 6x KaiHH 6x orangepascal 6x
 List of Learning Resources2015-05-05 10:20:32How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org