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 Professional Discussion / Different movement if underwater?

Author
Message
i lyke pineconez
15
Years of Service
User Offline
Joined: 16th Aug 2010
Location:
Posted: 9th Jan 2011 08:07 Edited at: 9th Jan 2011 08:10
I have a terrain, which has a small lake in it. When the player object is equal to or less than the water height, i want the movement to change so that the player moves in the direction they are facing.

Basically, it isnt creating the movement i need help with, im pretty sure i can do that. But right before i move my player normally, i want to run a check to see if theyre underwater, and if they are, move the player, and skip over the normal movement controls. Currently im using this:
but that doesnt seem to work, or if it does, it isnt any different than my normal movement. Any ideas how i could make this work?
SH4773R
16
Years of Service
User Offline
Joined: 18th Jan 2010
Location: AMERICA!!!
Posted: 9th Jan 2011 08:46
Iv got a head ache right now but it seems your running the normal movmant code no matter if you underwater or not.
Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 9th Jan 2011 09:22
In any case, always avoid goto's in functions! By doing this your function will never return to the return address... ever!
I suggest not to use gosubs either. Just place all code in functions. Eg. A function for collision, and use that function in the player movement function.

Cheers!
Sven B

SH4773R
16
Years of Service
User Offline
Joined: 18th Jan 2010
Location: AMERICA!!!
Posted: 9th Jan 2011 09:27
Oh, also u can't have functions inside of the main code it has to be at the end after a end command
i lyke pineconez
15
Years of Service
User Offline
Joined: 16th Aug 2010
Location:
Posted: 9th Jan 2011 19:37 Edited at: 9th Jan 2011 20:35
Quote: " Just place all code in functions. Eg. A function for collision, and use that function in the player movement function."
-- Well, i have already done that. For me it is a lot easier to just handle the movement and collision in the same function, but i guess i could separate it if you think it would help?

Heres what im currently using, I dont think i decribed it accurately the first time.


EDIT: I think I have found the problem, or one of them, anyway. Every time i try to do anything with the WaterHeight# variable and my player position, like putting: " if oldy# < WaterHeight# then oldy#=WaterHeight# " before the line " position object 2,x#,oldy#,z# ", it does nothing, so i think the problem is with the fact that i cant use the value of the variable for anything. I am using Evolved's Water Shader, and it clearly defines the variable, so I have no idea what im doing wrong.
Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 9th Jan 2011 21:29
It's easy to avoid using a goto, like this:



i lyke pineconez
15
Years of Service
User Offline
Joined: 16th Aug 2010
Location:
Posted: 9th Jan 2011 21:51
Thanks Sven, dont know why I didnt think of that.

However im still having a problem in the fact that when my players Y < WaterHeight#, nothing happens. For some reason its skipping right over the variable or something... the gravtiy is 0 once below WaterHeight#, so it should sit there and float, but the player continues to move downward like normal, and the movement is the same. When I enter the number itself instead of the variable, it works fine except for that I cant move, but entering the number presents a problem because I may need this number to change every so often.

Login to post a reply

Server time is: 2026-07-21 20:36:16
Your offset time is: 2026-07-21 20:36:16