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 / Need help with camera following character

Author
Message
Sazex
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location:
Posted: 15th Dec 2011 08:53 Edited at: 15th Dec 2011 09:35
OK, so I got this camera code for third person games, and I used it and it worked really well, except when I tried to center it to my character, the camera showed a lot of the ground, and I did not want that, so I created a box that would be just barely over his head/ on his head, but hidden, and have the camera follow that...

that made the camera move almost perfectly, just the way I wanted it to with the mouse, however...

I could not get the camera and the object to move flawlessly so I created separate controls for the box, so that the box and the character would both move at the same speed, but having no collisions set up on the box, the box kept moving away from the character, whenever I collided with a building

so I set the x and z coordinates of my camera to point and follow my character, and kept the y axis at the box, so now I can move the camera nicely, while it positions itself on the character,

but now the problem is that if I want my character to jump, (which I do), the camera wont follow him because its following the y axis for the box.

So can anyone help me? With trying to get my box to jump with my character, or in other words stay exactly where my character is at all times?

Any other way to fix this problem would be very welcome,

the main thing I need is a good camera for 3rd person that follows the character and where the character moves in the direction of the camera (this is not included in my code yet)
but most importantly, a camera that moves around the character with the controls of the mouse

I know the message is kind of long, so thank you for reading it if you did


here is my code:

object 1 is my character
object 5 is the box I am having the camera point to


here is a picture of what I am trying to do
http://i250.photobucket.com/albums/gg258/sazex/camerabox.png

and this is another picture of how the camera looks when its pointed at my character and not the box
(when I move the camera all the way down)
http://i250.photobucket.com/albums/gg258/sazex/nocambox.png

btw if anyone can point me to a good place to learn how to make my character double jump with sparkyscollision that would be awesome

sazex
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 15th Dec 2011 12:00
Just tagging in for now...

nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 15th Dec 2011 20:37
um, on my mobile, so cant read yr code but this sounds like it can be simplified.

You know your character's dimensions.
So, set the camera to follow:
object position x(character)
object position y(character) + modifier
object position z(character) + modifier
the modifier will be the height and distance from your character you want the camera to be, stored in a variable(s). That way you can control zooming for specific environments, Keep in mind that your character's xyz coordinate represents the exact center of the model so you need to factor that in. This approach should work fine. If you still wish to use an invisibox though, then position object yourbox with the modified coordinates i suggested. Hopefully, the simplest option works though

29 games
19
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 15th Dec 2011 21:10 Edited at: 15th Dec 2011 21:12
I haven't looked at the camera issue, wasn't there a simillar post on the DBPro board?

Anyway, as for the double jump, I'm guessing that you want to have the character jump then when it reaches the top of its jump the player can initiate a second jump.

The way to do this is to look at the y velocity of the player. At the top of it's jump it's velocity will be zero. I.e. it moves upward with a positive velocity, stops, then drops with a negative velocity. In practice, because of the way code work, the velocity may never actually be zero but be a positive value as it reaches the top of its jump then become negative in the next loop

Because of the way gravity works, the velocity, as the player drops will start at zero and "increase" (i.e. the magnitude gets bigger)

The trick to do a double jump, is to allow the player to initiate another jump if the sphere's y velocity is negative but has a low magnitude, i.e. the player is moving downward but not very fast. This then gives a "window of opportunity" for when the player can initiate a second jump.

The other complication is whether or not you want to the player to have to release the jump key and press it again at just the right moment to initiate the second jump.

Below is demo that shows the above in action. The way I deal with gravity and velocity is simillar to they way you've done it.



I've set it to chain together three jumps and you might want to player around with the variable "fall_speed_jump_limit#" as this effective determines when the player can initiate another jump.

As for collision, you shouldn't have to change anything as it does really interfere with the double jump. Once the player is in the air, collision with the ground doesn't matter any more.
Sazex
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location:
Posted: 16th Dec 2011 02:08 Edited at: 16th Dec 2011 02:09
@ nonZero, thanks! can't believe that worked!, but I actually have a new problem now, whenever I jump, another model of my character is created, (for as long as I am pressing the jump key) it is somewhat transparent and moves faster than my character (only when jumping)

this problem did not happen when I had the camera following the y axis of the camera,

I also tried to take a picture of it, and post it here, but it was not showing up, so I tried to record it on the screen, and it did not show up there either... weird...

@29games thank you very much for that code and explanation, I read through all of it, and tried to get it to work on my game as best as I could, with no results all it does is keep flying when I hold the jump key (spacebar)...

anyways here is my code now:


sazex
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 16th Dec 2011 11:49 Edited at: 16th Dec 2011 13:22
Okay, here's some (prolly unstable) code I just boiled up this morning. Think of it as a very crude concept. Perhaps it'll be useful. It should solve you dbl-model and your spacebar problem.
Use the direction keys to move and spacebar to jump. You can perform double-jumps too



EDIT: I have examined your code. The reason why you get that "copy of your object" is that you called the SYNC command mid-loop and then again at the end of the loop. The clone is actually your object, drawn twice because of the SYNC being done twice. Never call sync twice in a loop, always call it once at the end of the loop (apparently some versions of DBPro require an initial call before the loop. I cannot confirm this, sufficed to say my version doesn't require this). IMHO, you don't need to call SYNC at all. Just set the SYNC RATE above your main loop and that's that. The engine can handle the rest. Unless you absolutely need to control your refreshing due to resources (a situation which I've yet to encounter and I'm working on a program running around 1900+ 3D objects, 1500 of which are textured).

As for your jumping problem, take a look at the code I posted. You'll see what went wrong with your flags.

Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 16th Dec 2011 20:39 Edited at: 16th Dec 2011 20:40
Quote: "As for your jumping problem, take a look at the code I posted. You'll see what went wrong with your flags."

Actually, I don't think anything went wrong with his flags. From what I gathered he copy/pasted 29 Games's code but forgot to adapt it to his program.

Sazex, You've got two different variables, speedy# and yvel#. Yvel# is used for the jumping snippet and to increase ypos#. The problem is you position your object to a variable called y# and y# is increased by speedy#. The reason it flys is because of this line:

If spacekey() then speedy# = .99

and so it will keep flying. What you need to do is adjust your code so that you've only got one set of y and y-speed variables.

nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 17th Dec 2011 09:14
Quote: "From what I gathered he copy/pasted 29 Games's code but forgot to adapt it to his program."

Oh, yeah missed that
Was on another planet, maybe a parallel world... "Not enough coding mana" *Drinks "Blue-Mountain" coffee* [insert bubbly noise], 10% mana restored.

Quote: "Actually, I don't think anything went wrong with his flags... The reason it flys is because of this line:

If spacekey() then speedy# = .99"

That's what I meant by flag problems. There's a lack of consistency with his input flags for spacekey. He's got no flags to say "You can't keep holding space and going up forever" (Although that would make for an awesome level, eg anti-gravity pit lined with lazers and machine gun turrets that you have to reach the top of. Throw in a few tiny ledges with just enough room to slip into without being skewered and we're in business ... Why do I always go off at tangents?) Anyways, what I mean is:



Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 17th Dec 2011 10:09
Quote: "Oh, yeah missed that
Was on another planet, maybe a parallel world... "

Don't worry, it wasn't an easy find. It took me a couple of re-reads to work it out.

Quote: "That's what I meant by flag problems. There's a lack of consistency with his input flags for spacekey."

Oh I see. Yeah, I was only focused on the existing flags and not lack of flags. NonZero 1 : Hodgey 1

29 games
19
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 17th Dec 2011 20:14
The modern curse of copy-past.

@ Sazex

Like Hodgey said you need to adapt my code to your code.

You've also used the same values for gravity, initial jump speed, and so on. You will need to tailor these else you might still find that you character shoots up in the air. I notice you're using a value of 0.07 when moving the character. This is almost 300 times smaller than the value is used for the initial jump speed. This doesn't feel right to me.

What I'd do is print the current y position and y velocity of the character. This will then give you an idea if the basic code is working.

Quote: "...anti-gravity pit lined with lazers and machine gun turrets that you have to reach the top of..."


That would be cool.

Quote: "Why do I always go off at tangents?"


Maybe becasue...

Quote: "There's a lack of consistency with his input flags..."


nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 17th Dec 2011 21:32
@Hodgey: If it's a draw, reset the score, reset the world and everyone wakes up tomorrow with a vague memory of today that is assumed to be a dream. Then the puppet masters watch curiously to see if we'll repeat our same actions...

@29 games: lol, death by own words [insert wild tangent about robot-spiders].

@sazex: Like 29 games said, you need to test out your physics settings. Consider is how realistic you want the game's physics. A good starting point may just be to use earth's RL gravity http://en.wikipedia.org/wiki/Gravity_of_Earth and work from that, ie set you walkspeed, jumpspeed, etc relative to that. If you want something unrealistic (as all great games should be) you can always tweak things from there, ie make the hero jump 20 meters high. Just a thought, it may or may not be easier, depending on your personal style.

Sazex
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location:
Posted: 18th Dec 2011 04:34 Edited at: 18th Dec 2011 04:35
Thanks NonZero, the extra sync was causing the double character problem, its fixed now, and I looked at your code, it helped

@ Hodgey I actually did change my variables the first
go round, but that did not do anything (because I changed Speedy#
in place of grav# -- silly me )

Now I correctly replaced the variables, in 29games' code, and I fixed the numbers to match more to my game, and the jumping works perfectly but there's still one last problem I am having, my character double jumps only once...

by that I mean I jump and press jump again, and my character double jumps perfectly, but then I try it again and he wont double jump for the rest of the time I play the game, here's my code :



sazex
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 18th Dec 2011 06:17
Sazex, I think the problem is you still have a couple of ypos# variables near the end of the loop. I think they are supposed to be just Y# so try deleting the ypos# = ypos# + SpeedY# because you've already got inc y#, speedy# earlier in the loop and replace the other ypos# with y#.

Sazex
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location:
Posted: 18th Dec 2011 06:35
alright, I deleted the ypos#= ypos# + SpeedY#, and replaced Ypos# with Y#, but it didn't change anything



sazex
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 18th Dec 2011 06:39
I think you need to reset number_of_jumps to 0 not 1 in the last if statement.

Sazex
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location:
Posted: 18th Dec 2011 06:52
nope, unfortunately it didn't do the trick

sazex
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 18th Dec 2011 07:08
Umm, is rad# (in the last if statement) supposed to equal something? Since that's the only time it's being used it will equal 0.0 so essentially the last if statement is the same as:



So that might need changing.

Sazex
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location:
Posted: 18th Dec 2011 07:11
Oh yes, rad# is not supposed to equal something in my code, so
I changed it to 0.0 , but it did not solve the jumping problem

sazex
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 18th Dec 2011 07:17
Well, basically that last if statement says that if the object's y position is less than 0.0 it will reset the necessary variables for you to jump again. What you need to figure out is the value that the y position needs to be less than in order to reset those variables, maybe the y position of the level. You could also make it based on collision if you wanted. Up to you.

Sazex
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location:
Posted: 18th Dec 2011 12:52 Edited at: 18th Dec 2011 12:55
Well, I am really iffy on getting the program to reset the variables, and I have been trying it for a while now, I believe that the game reads the "max_number_of_jumps" as being the total amount of jumps the game will initiate.

I tried to change it, but I'm not sure how to have my code reset the "max_number_of_jumps" when my character hits the ground.

here's my most recent code:
right now my character just keeps jumping if I keep pressing the spacebar, I did this on purpose



the part i changed was the


changed inc "number_of_jumps" to "max_number_of_jumps"

sazex
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 18th Dec 2011 16:40 Edited at: 18th Dec 2011 16:41
Quote: "I tried to change it, but I'm not sure how to have my code reset the "max_number_of_jumps" when my character hits the ground."


I believe I adressed this issue in the code I posted earlier:

Quote: "

"

.... .... .... ... It's near the bottom of the code.
Sphere was the player, Object 1 was the ground.

However this'll only work on flat surfaces or terrain with a constant gradient. That's why Hodgey suggested collision detection. All you do is chack your player's collision with the ground. If it is true, reset whatever needs resetting.

I'm a little confused though. Are you trying to limit the player to n jumps at once, 2 jumps at once or infinite jumps? I ask because in your latest post you said you deliberately allowed the player to keep jumping ad nauseam. If the latter is the case I don't see much point in tracking the number of jumps.If either of formers are the the case, you need


Then if a jump's initiated:



Then, to check the player vs the terrain and do the reset:


Note that you can set collision detection per object to sphere-based, box-based or polygon-based collision.

Sazex
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location:
Posted: 19th Dec 2011 03:59 Edited at: 19th Dec 2011 04:02
Sorry, I should have been a bit more clear, I only had my character
jumping forever for testing purposes, and I just stated, how I did it.

What I want the game to do is have my character double jump, and
start to fall; once my character hits the ground,
I want max_number_of_jumps to equal 1 again.

^ thats where I am having problems, trying to get the game to detect,
the collision between my character (object 1) and the map (object 2)

I tried


but that did not work, so I thought maybe it was because I was using Sparkys collision,

So I tried this,


buut, sadly to no avail

sazex
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 19th Dec 2011 18:26
Quote: "What I want the game to do is have my character double jump, and
start to fall; once my character hits the ground,
I want max_number_of_jumps to equal 1 again."


The code you posted is correct, assuming sparky's collision's parameters are the same as the DBPro OBJECT COLLISION. Therefore, the problem must lie elsewhere in the code. Examine your variables carefully. I noticed you are using max_number_of_jumps to track your number of jumps or remaining jumps or whatever. You should consider heeding my earlier advice: If you have an absolute limit to how many jumps the player can perform, use a CONSTANT or just a number, ie 2. That will remain the same always. Use a GLOBAL variable to track the number of jumps that have been performed. If the GLOBAL = the CONSTANT, don't let the player jumps again. If the player hits the ground, set the GLOBAL to 0. So in other words, the GLOBAL has three possible values:
0 = Not jumping/falling
1 = Has jumped, can jump again
2 = Has exhausted jump limit.

If you suspect that the collision isn't detecting, simply run this to test:



If your program terminates upon contact with the ground then ya know the collision's working. Have another look at my example (the code I posted with the little ball that can't escape the psychedelic landscape). Double jumping works fine in that. If there is a problem with the collision, have a look at the different collision detection modes available and try them out. You can use an "invisible object" collision technique for uneven surfaces if polygon-collision's a little too slow. By this, I mean stashing a sphere underneath a bump and using spherical collision, etc.

29 games
19
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 20th Dec 2011 02:50
When I do "landing collision" using sparky's, I just ray cast or sphere cast straight down, use the "SC_getStaticCollisionY" command to calculate the ground height (I tend not to worry about sliding collision for jumping) then apply the logic:

if y position < ground height: the character has hit the ground so terminate jumping and reset all flags.

Just to reinforce what nonZero said.

The variable "max_number_of_jumps" is simply the maximum number of jumps that the player can chain togther and should not be altered by the jumping/falling/landing code.

The variable "number_of_jumps" keeps a tally of how many jumps the player has chained together and needs to be reset to zero once the player has landed. Therefore:

if number_of_jumps >= max_number_of_jumps then prevent the player from initiating any more jumps.

In this case, the variable "max_number_of_jumps" could be declared as a #CONSTANT and "number_of_jumps" could be declared as a global if you're using functions.
Sazex
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location:
Posted: 20th Dec 2011 09:16
Sorry this is taking a while to understand,
so object collision works after testing it,

If i am not supposed flag, meaning

if object collision (1,2) then spacekey_pressed = 0

but that did not get me anywhere

i put this-
if y# < 0
number_of_jumps = 0
speedy# = 0
endif

but that did not do anything, maybe I am getting the object 2 position (ground) incorrectly, how would I describe the position
of object 2 if need be?

sazex
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 20th Dec 2011 10:32
Quote: "If i am not supposed flag, meaning

if object collision (1,2) then spacekey_pressed = 0

but that did not get me anywhere"

It wouldn't because spacekey_pressed keeps track of the immediate spacekey input in regard to the jumping system. What I think you need to do is replace the:

if y# < 0

with

if object collision(1,2)

and then carry out the resetting of number_of_jumps and speedy#.

Sazex
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location:
Posted: 21st Dec 2011 04:28 Edited at: 21st Dec 2011 04:31
Alright, So I did this:

if SC_objectcollision (1,2)
Number_of_jumps = 0
SpeedY# = 0
endif

but I am having 2 problems with this,

First, At the beginning of the game, the character is colliding with the ground, so SpeedY# = 0, good,
but that now means that for as long as the game detects collision with the ground, SpeedY# = 0 (in other words no jumping at all. )

Second, If I get rid of SpeedY# = 0 then even though Number_of_jumps = 0, I can still keep mashing spacebar to jump forever, why does that happen?



sazex
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 21st Dec 2011 04:40 Edited at: 21st Dec 2011 04:41
Regarding the continuous jumping... I recall this issue from over a decade ago... my theory is the time it takes to reach the end of the loop or whatever is too long perhaps put it inside its own independent while end while or something like that so the flag is handled before the rest of the remaining code if this makes any sense at all...

I know while endwhile is a bad one but was just using it as an example...

Hope this helped...

EDIT

Code... typo

nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 21st Dec 2011 11:02
MrValentine is on the right track. It's the order of your code.

Try placing this:


ABOVE the code relating to jumping. In other words, check for collision 1st. If so, reset variables, if not, move on. Now check for jumping-related stuff. So if you press space, it'll reset your position once, then detect space, then move your object up, then loop. 2nd cycle: check collision(no collision found, move on)... and so and so. I may have mentioned earlier, but FLOW is very important. Hope this works (can't test it right now), but it should do.

Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 21st Dec 2011 12:16
I'm afraid the order may be somewhat irrelevant in this case. It all depends on the collision box/sphere/shape. If the collision box is big enough, it could detect collision for multiple iterations even once the spacebar has been pressed and the jump has been initiated thus cancelling it out. If it isn't, then nonZero's code should work.

But if it is, we might introduce another flag. Try nonZero's first, if that doesn't work then try this:



Let us know how you get on.

nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 21st Dec 2011 15:09
@Hodgey: Good point, I didn't consider the size of the collision box vs how many units he'll move up in the first cycle. I assumed that a single unit of jumping would clear the collision box (It works fine for what I'm working on atm, but with 3D there are sooooo many factors).

@Sazex: If the order of your code is:
1.Start Loop
2.Collision check w/ ground
3.Check player input
4.Move player if jumping.
5.End loop
AND the distance your character moves in one cycle of your loop will place him above the ground's collision bounds, then it will work fine. Otherwise it will fail, because:

Thought I'd just explain things in case you were wondering WHY it did/didn't work.

72 97 112 112 121 32 72 111 108 105 100 97 121 115 32 112 112 108 33

Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 22nd Dec 2011 01:26
Thanks nonZero, I should have explained myself a bit more but you've done a great job in doing it.

Just for clarity, when I said that the order was 'somewhat irrelevant' what I meant was, it wasn't the cause of the problem. The difference of having the collision check before the jumping code as opposed to having it after is that if it's before, it saves you one iteration if the collision condition is true. However, you won't be able to tell the difference mid-game.

nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 22nd Dec 2011 07:48 Edited at: 22nd Dec 2011 07:50
Here's an example visually of WHY I said to do the collision checking BEFORE your KEYSTATE CHECKS and variable updates. This is why code-structure is important.

In this scenario, collision is checked first:


In this second scenario, collision is checked AFTER the keycheck. This NULLIFIES the modifications done because the entity has not yet been repositioned and thus responds to the collision check.



As you can see, I've commented out the unwanted collision checks for each scenario to make it more readable.

The first scenario jumps fine because:
Collision = 1 --> Set player yvelocity to 0
Keystate = jump --> Set player yvelocity to -1
Update player position

The second scenario fails because:
Keystate = jump --> Set player yvelocity to -1
Collision = 1 --> Set player yvelocity to 0 (uh-oh!)
Update player position

Something to think about too is handling of sprites. None of my UDT data was actually necessary!

EDIT: About the "grownd" constant in my code. I CAN spell but you can't use keywords in constant names. Just in cayse enney wun thort I can not spell

72 97 112 112 121 32 72 111 108 105 100 97 121 115 32 112 112 108 33

Sazex
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location:
Posted: 24th Dec 2011 10:32
Sorry it took me a while to respond, but the order did not change the problem

Also, Hodgey I tried the code you gave, but didn't work, on a side note can I get you to explain what defining 'collided' as boolean means?

And NonZero, I have not completely looked at your hints yet, but maybe if I do, I might be able to fix it

sazex
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 24th Dec 2011 10:57
Quote: "on a side note can I get you to explain what defining 'collided' as boolean means?"

A boolean can only be of two possible values, 0 or 1 (false or true respectively in some languages) and that's all we need for the 'collided' flag, whether the collision is true or false.

At this point in time we might need the physical project to help out any further. It's more efficient for nonZero and myself to work with the project than to take educated guesses.

Sazex
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location:
Posted: 24th Dec 2011 12:53 Edited at: 2nd Jan 2012 01:17
Ok attatched files to post

entire code:



sazex
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 24th Dec 2011 21:16 Edited at: 24th Dec 2011 21:18
Ok, try this:



The problem was you had my if statements inside another if statement making them dependend on that condition being true when they needed to be on their own.

Sazex
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location:
Posted: 25th Dec 2011 03:38
Thanks! I did not see that, but, does the double jump work for you?

Because for me if I repeatedly press the space bar, my character still keeps jumping up...

I think that if I have number_of_jumps = Max_number_of_jumps then I should have my game make it so that no more jumps can be initiated
but I dont know how to do that

sazex
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 25th Dec 2011 03:48
IF JUMPS = 2
CAN JUMP = 0
ENDIF

something along those lines... basically it means you need to add a check for can jump before the jump function and if it equals 0 then do not allow them to jump and just end the function.

If that makes sense...

Sazex
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location:
Posted: 25th Dec 2011 06:06 Edited at: 25th Dec 2011 07:01
Actually I was thinking more along the lines of this:

If number_of_jumps = max_number_of_jumps then "drop" player
^ but I need to define how to "drop the player", and have it so that
space bar does not work in the time period of the drop

and have number_of_jumps = 0 when object collision (1,2),
^ this one is already done though,

sazex
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 25th Dec 2011 16:37 Edited at: 25th Dec 2011 16:39
Quote: "I need to define how to "drop the player", and have it so that
space bar does not work in the time period of the drop"


So the space-bar does not work after max jumps:


That's just one way of doing it. Basically, so long as your jumps are under 2, checks for spacebar are made. But if your jump number is 2, no checks for space are performed.

72 97 112 112 121 32 72 111 108 105 100 97 121 115 32 112 112 108 33

Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 26th Dec 2011 10:52
Ok, I think I've got it.




What I've done is ditched the collision check and based it on the y values. Basically, it gets the y value of the object before it jumps and then checks against that value when deciding to reset the values so in psuedocode:

if current y value <= y value before jump
reset the number of jumps and speed
endif

There is a potential problem with this code though. If you tried to land on ground lower than the ground you jumped off it might stop in mid air. If you want to fix this then you may need to look at polygon collision or some for of collision that's somewhat based on the landscape's shape.

Sazex
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location:
Posted: 1st Jan 2012 08:18
Ok, sorry it took me so long again, but I was on vacation, anyways
thank you nonzero for that explanation

And thank you Hodgey, the double jump, finally, is working perfectly!

sazex
Sazex
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location:
Posted: 2nd Jan 2012 10:11 Edited at: 2nd Jan 2012 10:11
Actually-scratch that last statement- the jumping does not work
on the top of the buildings --
Quote: "If you want to fix this then you may need to look at polygon collision or some for of collision that's somewhat based on the landscape's shape."


How would I change it to polygon collision?

sazex
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 2nd Jan 2012 12:16
Quote: "How would I change it to polygon collision?"

On my ipad right now so off the top of my head it's a parameter in sparky's setupComplexObject function. Refer to the documentation for that one. There is a performance cost with polygon collision however but I do believe sparkly's offers an alternative, using nodes or something similar, Again you'll need to refer to the documentation for that one.

Sazex
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location:
Posted: 3rd Jan 2012 03:47 Edited at: 3rd Jan 2012 04:07
Im having troubles with the sc_setupcomplexobject thing, I think I should have the number of jumps performed just reset when I hit the ground(object2), in my case, object 2 includes everything that I will have my character walk on, including the buildings.

So I'm going to retry the ground collision, and have the number of jumps =0 when max number of jumps is reached and have my character not be able to perform anymore jumps when numberofjumps=maxjumps

Edit:
well after reverting my code:



I tried this to see if the game detects if number_of_jumps=max_number_of_jumps


but it did not work , if I do get it to work, then I want to try this


and here I want to make it so that spacekey doesn't work, but I also do not know how to do that(make spacekey not work for the time being of the drop, or until object collision between the character and the level)

So can anyone tell me why



^that does not work?

and help in how to disable spacekey?

sazex
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 3rd Jan 2012 09:17
Quote: "I tried this to see if the game detects if number_of_jumps=max_number_of_jumps "


According to the full source code you posted, you have not declared max_number_of_jumps as a GLOBAL. Consequently the program will treat it as a LOCAL, meaning the memory your variable in the main program is pointing to is different from that of the memory your variable in your function is pointing to (even if they have the same name). You must declare global variables, though personally, if I work with a single-digit constant number, I generally just use the number anyway, lol

Quote: " ...but I also do not know how to do that(make spacekey not work for the time being of the drop, or until object collision between the character and the level... "


I would recommend not disabling jumping during a fall as it would make gameplay exceeding tough and frustrate the player as s/he would need perfect timing for double-jumps. Still, if you want to disable jumping while falling, you can either:

1. Create a flag, eg: "player_falling" [= 1/ = 0]
2. Use the y-velocity as a flag, eg: If y-velocity > 0 then you can press space (if the other conditions are met).

Ultimately, you may want to go with option 1 because you have a number of "events" that trigger be allowed/denied the ability to jump. For manageability's sake:



So in other words, run a check on conditions and simply query 1 variable (you CanJump flag) before checking for a space press.
PROS: Easier for beginners, more manageable code
CONS: Re-writing portions of code, extra condition checks per cycle.
It's up to you.

Hope this solves some/all your problems.

Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 3rd Jan 2012 11:37 Edited at: 3rd Jan 2012 11:38
Quote: "According to the full source code you posted, you have not declared max_number_of_jumps as a GLOBAL. Consequently the program will treat it as a LOCAL, meaning the memory your variable in the main program is pointing to is different from that of the memory your variable in your function is pointing to (even if they have the same name)."

But he hasn't made any functions so scope isn't really an issue...is it?

I've noticed that you aren't using sparky's sc_objectcollision command and I don't know if DBP's collision commands work with sparky's collision system.

Also, try adding this command before your main loop:

sc_drawObjectbounds 2

This draws a wireframe of the collision shape of the specified object. I got some unexpected results with your landscape. Not saying that it's your fault but I've never seen anything like it. I'm not quite sure how to tackle this.

nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 3rd Jan 2012 17:14
Quote: " But he hasn't made any functions so scope isn't really an issue...is it? "


My bad, I just saw the top part amidst other GLOBALS and assumed that he'd stuck his stuff in a function.

nonZero defends with "Poor Defense 1"
I mean why declare globals if you don't need to?
+100 HP Restored
nonZero HP = 1265/1500


Hodgey (and everyone looking at this thread) attack with "Meme number 2164"
"Assumption is the mother of all [censored by mod]"
9999 Damage
nonZero HP = 0


nonZero died

Roll dice...

Yaay, Disney Death! Was just badly injured!
nonZero awakes in a LOCAL inn.
Innkeeper: "You sure are lucky son, be careful NEXT time!"

Back to the issue at hand, perhaps the problem with your jumping:
Quote: "I tried this to see if the game detects if number_of_jumps=max_number_of_jumps"

is here:

judging by your variable names, shouldn't you be increasing "number_of_jumps" as you're increasing the maximum allowed jumps atm. As for the collision problems, can't be sure but try fixing this so long.

btw: Sorry about the function mixup. I'm just so used to things being in functions that if I see a global I make an assumption due to mind association. Kinda like this:
Quote: "
Aoccdrnig to a rscheearch at Cmabrigde Uinervtisy, it deosn't mttaer in waht oredr the ltteers in a wrod are, the olny iprmoatnt tihng is taht the frist and lsat ltteers be at the rghit pclae. The rset can be a toatl mses and you can sitll raed it wouthit porbelm. Tihs is bcuseae the huamn mnid deos not raed ervey lteter by istlef, but the wrod as a wlohe."

In my case, the "human" mind did not read the entire code.

MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 3rd Jan 2012 17:50
nonZero... I salute you

Login to post a reply

Server time is: 2024-11-24 03:11:12
Your offset time is: 2024-11-24 03:11:12