Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Collision Seems shocky.can you help me fix it?

Author
Message
Silvester
18
Years of Service
User Offline
Joined: 7th Dec 2005
Location: Netherlands
Posted: 9th Dec 2006 18:05
OK,i coded my first working collision with terrains.

However.my collision has side-effects.it looks like a continueing earthquake.Further it works fine.

Here is how it works in basics:

0 /
______/
The 0 will drop down til it hite the _

o/
____/

The o is going up till the collision is 0

0
------
Collision.its schocky!

Here is my code.



And aatached it my Terrain.X

Please help me.

...No Signature here...

Attachments

Login to view attachments
TEH_CODERER
21
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 9th Dec 2006 19:12
I'm sorry but that collision code is awful. I recommend Sparky's dll. If you need any help after than then let me know.

Silvester
18
Years of Service
User Offline
Joined: 7th Dec 2005
Location: Netherlands
Posted: 9th Dec 2006 19:51
1) I have tried many MANY collision plugins,wich i all trew away because they where so darn difficult.

2)THIS IS MY FIRST WORKING TERRAIN CODE.

3)Why is it so bad anyway?

...No Signature here...
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 9th Dec 2006 21:05
Collision is shaky because you continuously move up the sphere and the cam as soon as it touches the terrain and move it back down as soon as it doesn't collide anymore, therefore you're continuously moving plus/minus a few units along Y#

The only way is to detect what it is the actual terrain height at sphere position and put sphere and cam there.
By casting a vertical ray with intersect object command from very high from terrain and to very low beneath it, you get the hit spot along Y# axis and can calculate the Y# position precisely .

Try this

Noonster
18
Years of Service
User Offline
Joined: 10th Jul 2006
Location: Idaho, USA
Posted: 9th Dec 2006 21:28 Edited at: 9th Dec 2006 21:31
EDIT: I see Scorpyo answered while I was taking my sweet time with it. Sorry

POD, here's what's wrong:

The "shocky" movement is because of your coding in the Collision() function. Once the sphere reaches the terrain surface, then each time the function is called (each iteration of the DO LOOP), the sphere is fluctuating up and down by 2 units. First, the collision is detected as being true, so the Y value is increased by 2 units and the sphere is displayed on the screen. Next, the collision is detected as being false, so the Y value is decreased by 2 units and the sphere is displayed on the screen...and this just goes back and forth. The fact that you have the camera tied to the sphere (by assigning the same coords) makes it appear that the terrain is doing the shocky movement, but it is actually the sphere. If you keep the camera fixed in one place, you will see this.

Don't take it as an insult, or be discouraged, by what TEH_CODERER said, but I have to agree; use Sparky's DLL. Why try to reinvent the wheel? I personally use NG Collision and really like it. However, Sparky's is free and many many people here seem to really like it too. There are many other areas of your programming skills to hone than to worry about writing a new collision detection program at this point. Again, I don't mean to insult; I'm still pretty new to all of this, and would not tackle such a project at this time.
Silvester
18
Years of Service
User Offline
Joined: 7th Dec 2005
Location: Netherlands
Posted: 10th Dec 2006 10:13 Edited at: 10th Dec 2006 10:30
Quote: "Collision is shaky because you continuously move up the sphere and the cam as soon as it touches the terrain and move it back down as soon as it doesn't collide anymore, therefore you're continuously moving plus/minus a few units along Y#

The only way is to detect what it is the actual terrain height at sphere position and put sphere and cam there.
By casting a vertical ray with intersect object command from very high from terrain and to very low beneath it, you get the hit spot along Y# axis and can calculate the Y# position precisely ."


OK,so i made it go up and down all the time...

Quote: "Don't take it as an insult, or be discouraged, by what TEH_CODERER said, but I have to agree; use Sparky's DLL. Why try to reinvent the wheel? I personally use NG Collision and really like it. However, Sparky's is free and many many people here seem to really like it too. There are many other areas of your programming skills to hone than to worry about writing a new collision detection program at this point. Again, I don't mean to insult; I'm still pretty new to all of this, and would not tackle such a project at this time. "


I have try'd all free Collision Plugins.
However,none of them are easy enough to understand.or they gave me errors.

Scorpyo,ill try your code as soon as i can.

EDIT:Scorpyo,the code seems to be letting me hang at a height of 10000...

...No Signature here...
TEH_CODERER
21
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 10th Dec 2006 10:57
Sparky's dll couldn't be easier!

Basically set up your terrain object at the start with:

sc_setupcomplexobject ID,GroupID,TrisPerNode
eg.
sc_setupcomplexobject 1,0,2

Then in your loop use raycasting:
d#=sc_intersectobject(ID,oldx#,oldy#,oldz#,newx#,newy#,newz#)
Which in your case will be from current x,y,z position of the camera to a point directly below. The value returned to d# will be the distance between the camera and the terrain. Then if this distance is smaller than the height the camera should be from the terrain you adjust accordingly.
eg.
if d#<10.0
position camera camera position x(),camera position y()+10.0-d#,camera position z()

Hope that helps.

Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 10th Dec 2006 12:29
- Scorpyo,the code seems to be letting me hang at a height of 10000... -

I have re-checked and it works perfectly here
Silvester
18
Years of Service
User Offline
Joined: 7th Dec 2005
Location: Netherlands
Posted: 10th Dec 2006 16:39 Edited at: 10th Dec 2006 16:41
Weird,let me try it at this computer.

EDIT:

OK,the problem is my dads computer.cause on mine it works perfectly,Thanks

...No Signature here...

Login to post a reply

Server time is: 2024-11-26 05:54:09
Your offset time is: 2024-11-26 05:54:09