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.

DarkBASIC Discussion / wierd collision problem

Author
Message
kRx
20
Years of Service
User Offline
Joined: 2nd Apr 2005
Location: Canterbury, Kent, UK
Posted: 23rd Aug 2005 23:33
i am using the following to make a collision



the problem is that once the collsion happens i cant get the character to move again. i spent the last few hours trying and its driving me insane. i am using this instead of '
if object collsion(1,2) etc, as when dist# is at a certain value and a key is pressed i want something to happen.

any help/advice massivly appreciated

thanks

kR

kR
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 23rd Aug 2005 23:47 Edited at: 23rd Aug 2005 23:51
You can't have the float variable X#2.

X2# is OK. (The # must be at the end of the variable name).

It might work if you change that, but I can't test it without the rest of the code.

Also, just noticed that if the dist is less that 40 (on the x/z), all you are doing is moving the object from what it was on the Y axis to 10. It will still be within the 40 limit.

Try positioning it using the X and Z rather than the Y and immediately testing the distance again, adjusting the X and Z values until you are outside the 40 radius.

TDK_Man

kRx
20
Years of Service
User Offline
Joined: 2nd Apr 2005
Location: Canterbury, Kent, UK
Posted: 24th Aug 2005 00:26
hey

sorry but i didnt understand what u ment in the 2nd part what u wrote. here is some example code



the problem seems to be that once dist < 40 the object is never going to move ever but i cant get the object out of taht radius once its entered it. anyway i think thats the problem

thanks

kR

kR
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 24th Aug 2005 01:21 Edited at: 24th Aug 2005 01:24
OK, if your program tests for collision by calculating the distance between you and the object, you decide at what distance the collision occurs.

So you used 40 and the program tests if the distance is less than this.

Once it is, a collision occurs and in your first snippet, you did this:

position object 1,X#,10,Z#

I didn't know what X# and Z# were without seeing more code. But I know that it's setting the HEIGHT of the object to 10 - regardless of what it was before.

If X# and Z# hadn't changed, then after moving it to Y=10, then it's probably still inside the 40 distance you set, so the program will continuously lock in a 'collision mode' loop, repeatedly positioning the object at X#,10,Z# - meaning that you can't move it.

What I was suggesting is that on collision, you use a little loop continuously backing up along the X and Z axis, testing for the distance each time you move the object back. As you used MOVE to move the object forwards, then you can also use MOVE -Value to back up.

When the distance is greater than 40, then you would drop out of this loop, at which point, the program would not register as a collision and you would be able to move the object elsewhere.

The code layout would look something like:

Distance is less than 40, so collision...
*** Loop start ***
Step back 1 unit with Move Object 1,-1
Test distance
If distance is still less than 40 continue loop
If distance is greater than 40 then exit loop and continue prog
*** Loop end ***

Hope that makes it a bit easier to understand.

TDK_Man

kRx
20
Years of Service
User Offline
Joined: 2nd Apr 2005
Location: Canterbury, Kent, UK
Posted: 24th Aug 2005 03:04
X# and Z# is the object position its towards the bottom of that sample. im stil not followin ya, maybe cos its 1 am ill try again tomo when im concentrating

thakns

kR
kRx
20
Years of Service
User Offline
Joined: 2nd Apr 2005
Location: Canterbury, Kent, UK
Posted: 24th Aug 2005 16:51
is this what u ment? this nis the instruction i added to my code and its kinda doing what i want it to do, looks a bit strange geting forced back 1 when hit something cant complain

thanks, let me know ive ive again misunderstood

kR

kR

Login to post a reply

Server time is: 2025-05-22 13:07:08
Your offset time is: 2025-05-22 13:07:08