Collision callback always returns true!!

joehot200
Posts: 15
Joined: Wed Apr 23, 2014 9:47 am

Collision callback always returns true!!

Post by joehot200 »

Hi, I am coding a server for a ship game (Been wanting support for a while but taken me 4+ months find the answer to the questions so I can register), and have decided to use JBullet as my library.

Since JBullet has no help forum, I am hoping that I can get help here.

My problem is that the collision callback always returns true, using this code (http://pastebin.com/7sFCScH0) which I have converted into java (http://pastebin.com/YKH3e6jH).

However, my hit variable in the code converted to java is always returning true!

Is anyone able to tell me what I am doing wrong and how I can fix it? Thanks.

As a sidenote, the JBullet code is on a server, and not a client.
simo.nikula
Posts: 1
Joined: Wed Apr 23, 2014 2:04 pm
Location: Lappeenranta

Re: Collision callback always returns true!!

Post by simo.nikula »

joehot200 wrote:Hi, I am coding a server for a ship game (Been wanting support for a while but taken me 4+ months find the answer to the questions so I can register), and have decided to use JBullet as my library.
I was wondering why you decided to use JBullet. Making such port has probably been interesting but in general using ports that are no longer developed may cause extra issues.
joehot200 wrote:My problem is that the collision callback always returns true, using this code (http://pastebin.com/7sFCScH0) which I have converted into java (http://pastebin.com/YKH3e6jH).
However, my hit variable in the code converted to java is always returning true!
It is difficult to figure out what you are trying to do. Both code fragments only modify local variables.
Java code also prints out message if distance is negative but I that it is common scenario during collision analysis.
Check e.g.
http://www.bulletphysics.org/Bullet/php ... &view=next
joehot200 wrote: Is anyone able to tell me what I am doing wrong and how I can fix it? Thanks.
It would probably help if you
- learn enough C++ so that you can use bullet directly
- learn math (at least if dot product was difficult question during registration) and physics
- get familiar with software debugger so you can analyse issues in your programs and study existing bullet examples while they are running
joehot200
Posts: 15
Joined: Wed Apr 23, 2014 9:47 am

Re: Collision callback always returns true!!

Post by joehot200 »

simo.nikula wrote:
joehot200 wrote:Hi, I am coding a server for a ship game (Been wanting support for a while but taken me 4+ months find the answer to the questions so I can register), and have decided to use JBullet as my library.
I was wondering why you decided to use JBullet. Making such port has probably been interesting but in general using ports that are no longer developed may cause extra issues.
joehot200 wrote:My problem is that the collision callback always returns true, using this code (http://pastebin.com/7sFCScH0) which I have converted into java (http://pastebin.com/YKH3e6jH).
However, my hit variable in the code converted to java is always returning true!
It is difficult to figure out what you are trying to do. Both code fragments only modify local variables.
Java code also prints out message if distance is negative but I that it is common scenario during collision analysis.
Check e.g.
http://www.bulletphysics.org/Bullet/php ... &view=next
joehot200 wrote: Is anyone able to tell me what I am doing wrong and how I can fix it? Thanks.
It would probably help if you
- learn enough C++ so that you can use bullet directly
- learn math (at least if dot product was difficult question during registration) and physics
- get familiar with software debugger so you can analyse issues in your programs and study existing bullet examples while they are running
I have a lot of useful code in java that I dont want to lose by switching to C++. Currently, I am using LWJGL and JBullet which if I ever switch to C++ can make me go to OpenGL and Bullet. I see no use in wasting time with a new programming language when what I really want to learn is how to make a game and the logic of making one.
Also, the code I gave uses no outside variables. You say it only modifies local variables, but thats correct. There is no code I am not showing you that modifies any other variables. I am just using code from the documentation which I am presuming you are familiar with.
I was told that the java code I was given should work, and I dont know much about this collision distance thing, just that it should work.
I strongly dislike your comment about learning math. I dont know the question mainly because I am 14 and have not covered that yet. Criticizing me for lack of knowledge is like criticizing an old person because they are not so familiar with computer technology. As it happens, it was mainly that george oswell thing which I could not find, because the question was asking about how many books he wrote and the answer was a year.... (unless he wrote almost 2000 books).
I am looking for a software debugger, but I did not know if this forum was the correct one for it. I have been flamed on other forums for asking that question, even though it is supposedly in the list of questions that I can ask.

But using Bullet does not directly solve my problem, so I am still looking for an answer.
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

Re: Collision callback always returns true!!

Post by xexuxjy »

JBullet is pretty old and behind the main bullet codebase , but it should be ok for what you want to do below. I also couldn't see anything immediately obvious with your java code.

Have you tried setting up a simple test with only two objects, moving closer togehter and making sure that the collission only occurs where you expect it to?

Something else to check maybe is that the Manifold Points are being initialised correctly, JBullets probably pooling them and they may not have clean/correct values.
c6burns
Posts: 149
Joined: Fri May 24, 2013 6:08 am

Re: Collision callback always returns true!!

Post by c6burns »

joehot200 wrote:(Been wanting support for a while but taken me 4+ months find the answer to the questions so I can register)
Wait, it took you 4 months to find out that the opposite of concave is convex?
joehot200
Posts: 15
Joined: Wed Apr 23, 2014 9:47 am

Re: Collision callback always returns true!!

Post by joehot200 »

c6burns wrote:
joehot200 wrote:(Been wanting support for a while but taken me 4+ months find the answer to the questions so I can register)
Wait, it took you 4 months to find out that the opposite of concave is convex?
Please read the thread and all the replies before commenting.


Anyway, I was fed up of bullet, I went for my own collision detection system:

Code: Select all

while (true){
			
			try{
				if (GameServer.ballss != balls){
					balls = (ArrayList<CannonBall>) GameServer.ballss.clone();
				}
				if (GameServer.players != people){
					people = (ArrayList<Clients>) GameServer.players.clone();
				}
				ArrayList<CannonBall> remcan = new ArrayList<CannonBall>();
				for (Clients cl : people){
					this.sleep(1);
					for (CannonBall can : balls){
						int distancex = (int) ((int) can.x - cl.x);
						int distancez = (int) ((int) can.z - cl.z);
						distancex = (int) (distancex * Math.sin(Math.toRadians(cl.rotation)));
						distancez = (int) (distancez * Math.cos(Math.toRadians(cl.rotation)));
						try{
							int i = GameServer.coords[GameServer.DELTA + distancex][GameServer.DELTA + distancez];
							if (i == 1){
								System.out.println("Collided!");
								remcan.add(can);
								cl.damage-=(100 + Math.random()*25);
								//if (cl.damage < 0){
								{	cl.sinking = true;
								}
							}
						}catch (Exception e){
							//System.out.println("Not collided.");
						}
					}
				}
				for (CannonBall ball : remcan){
					balls.remove(ball);
					GameServer.ballss.remove(ball);
				}
                           }
c6burns
Posts: 149
Joined: Fri May 24, 2013 6:08 am

Re: Collision callback always returns true!!

Post by c6burns »

joehot200 wrote:Please read the thread and all the replies before commenting.
Trust me, I did.
joehot200
Posts: 15
Joined: Wed Apr 23, 2014 9:47 am

Re: Collision callback always returns true!!

Post by joehot200 »

c6burns wrote:
joehot200 wrote:Please read the thread and all the replies before commenting.
Trust me, I did.
I guess you missed this?
As it happens, it was mainly that george oswell thing which I could not find, because the question was asking about how many books he wrote and the answer was a year.... (unless he wrote almost 2000 books).
c6burns
Posts: 149
Joined: Fri May 24, 2013 6:08 am

Re: Collision callback always returns true!!

Post by c6burns »

Well this is clearly off topic, but I'm not sure you have any high ground to stand on if it took you 4 months to find out the title of Orwell's most famous book (besides possibly Animal Farm).
joehot200
Posts: 15
Joined: Wed Apr 23, 2014 9:47 am

Re: Collision callback always returns true!!

Post by joehot200 »

c6burns wrote:Well this is clearly off topic, but I'm not sure you have any high ground to stand on if it took you 4 months to find out the title of Orwell's most famous book (besides possibly Animal Farm).
Where is your ground?

It says "Type in george oswell's famous book (a number)". Since your reply is not a number, then I am obviously confused as to why you supposedly have the "High ground". I will keep defending myself, because I see no reason not to. I see no ground that you have to stand upon, and so I am going to continue stating valid points until you do.

If you dont want to go offtopic, stop responding.
c6burns
Posts: 149
Joined: Fri May 24, 2013 6:08 am

Re: Collision callback always returns true!!

Post by c6burns »

Hey I admit I only skimmed your thread. I'm not overly interested in java implementations. But you can admit you didn't research the answer to the Orwell question for 4 months.
joehot200
Posts: 15
Joined: Wed Apr 23, 2014 9:47 am

Re: Collision callback always returns true!!

Post by joehot200 »

c6burns wrote:Hey I admit I only skimmed your thread. I'm not overly interested in java implementations. But you can admit you didn't research the answer to the Orwell question for 4 months.
I can to a certain extent. I did google it a few times, but spent less than 2 minutes on each attempt. I have to agree that I didnt try very hard, and eventually found the answer to the question in a yahoo answer.
User avatar
L83
Posts: 2
Joined: Tue Jul 29, 2014 1:56 pm
Location: France

Re: Collision callback always returns true!!

Post by L83 »

Yare Yare Daze~ !! It's easy though when you have some knowledge !! Well, Wikipedia is your friend !! But 4 month for a name of a famous author's book which is a number... Are you kidding us ? Is that a kind of a joke ?
STTrife
Posts: 109
Joined: Tue May 01, 2012 10:42 am

Re: Collision callback always returns true!!

Post by STTrife »

You could also consider using a different physics engine that works Java and where the java port is still updated, or maybe a physics engine that is built in Java.
It seems like you are going to have a hard time if you cannot debug the bullet code itself, and the java port is not maintained any longer. Then if one thing doesn't work as you expect, you are probably stuck for good, and all the work you have done is going to waste. I know it sucks to change now or abandon you code and continue in C++ but in the long run it seems like a much better solution.

A long time ago I used ODE in Java that worked fine...
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: Collision callback always returns true!!

Post by Basroil »

joehot200 wrote: However, my hit variable in the code converted to java is always returning true!

Is anyone able to tell me what I am doing wrong and how I can fix it? Thanks.

As a sidenote, the JBullet code is on a server, and not a client.
Well, from that code if there are contact points you are almost guaranteed to have a "hit", and in many cases multiple hits. Contact points can be when surfaces collide, but also when one object is inside another. If the object passes through another object, then things start to get complicated depending on what version you're using. Perhaps you mistakenly put two objects inside one another?

On another note, the checking of classes to each other is kind of iffy, since I'm not sure jBullet returns a class pointer (which can be checked by !=) or a copy of the class (which would make objects 1 and 2 be different even if they describe the same object).
joehot200 wrote: I see no use in wasting time with a new programming language when what I really want to learn is how to make a game and the logic of making one.
1)You can never waste time learning C/C++, it's the reason why java is around in the first place, and the syntax is very similar (with keyword differences). Only major difference is in how stack management and pointers are used, at least for the tests you want to use.
2) The logic of making a game engine is 50% game engine design, 50% solving coding problems in engine design, so logic = learning the language. The logistics of making a game and making a game engine are completely different though, and why you generally see teams of people working on one with input from the other. You don't need to program to learn logistics of game design, but in that case you need to excel at something else, be it story, art, or management.
joehot200 wrote:I strongly dislike your comment about learning math. I dont know the question mainly because I am 14 and have not covered that yet. Criticizing me for lack of knowledge is like criticizing an old person because they are not so familiar with computer technology.
Your software education should begin with math and have math continue throughout. A programmer who doesn't understand math is nothing more than a monkey at a keyboard, banging away hoping he has the right order of letters to make something work. If you don't know something, go to a library and check out a book on it. When I was in middle school I was already doing linear algebraic problems to solve for solutions, even using Bayesian algorithms (unintentionally) while writing simple calculator games (and solvers so I didn't have to do algebra homework). There's plenty of resources now that weren't around in my time, so your age has nothing to do with your ability to learn.

joehot200 wrote:As it happens, it was mainly that george oswell thing which I could not find, because the question was asking about how many books he wrote and the answer was a year.... (unless he wrote almost 2000 books).
Another part of a software engineer's job is to be well rounded and understand the world, not just how to make fuzzy shapes clash together. You really should be familiar with the book, after all, many software companies draw inspiration from it for commercials and tag lines (including apple).
joehot200 wrote:I am looking for a software debugger, but I did not know if this forum was the correct one for it. I have been flamed on other forums for asking that question, even though it is supposedly in the list of questions that I can ask.
I assume you're using Eclipse or NetBeans, both have debugging and profiling built in or available as an extension. It's almost a joke to search for that though, and likely why people attacked. Perhaps you should be asking "what debugger do you recommend?"
joehot200 wrote:But using Bullet does not directly solve my problem, so I am still looking for an answer.
So you've tried C++ code with bullet then? Just before you stated that you would not even try it.
joehot200 wrote:Anyway, I was fed up of bullet, I went for my own collision detection system:
That's not collision detection, that 's overlap detection, and not a very good one at that because you keep casting back to integers at each step... Which means your x distances will be zero between about -60 degrees and +60 degrees! What you should do instead is subtract the ball and player positions and test against a threshold that is equal to the player radius in the direction of the ball and the radius of the ball (using absolute values of course), then if necessary convert to integers for display. Integer only collisions won't work in bullet with expected results, since it was made with floating point math in mind.
joehot200 wrote:I have a lot of useful code in java that I dont want to lose by switching to C++. Currently, I am using LWJGL and JBullet which if I ever switch to C++ can make me go to OpenGL and Bullet.
Why are you using a game client package for the server? A server program should have no graphics or input of it's own, it should simply be a way of connecting clients in a meaningful way (that's not to say a server instance can't also have a client program running for things like live video feeds). You do NOT need ogl to use bullet, and indeed it runs far faster without it. What you might need is a UDP or TCP/IP framework to communicate with your clients, but those are available at github, sourceforge, etc.
Post Reply