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 / Camera Collision and Camera as radar.

Author
Message
Ramon156
13
Years of Service
User Offline
Joined: 13th Jul 2011
Location: Netherlands
Posted: 16th Mar 2012 17:57 Edited at: 16th Mar 2012 18:18
Hello again, first of all thank you for putting your time and energy into helping me and possibly other people.
I have a few questions regarding to camera movement.

First some details about the game.

* My game is going to be in a third person view behind the player.
* The radar will be a camera positioned above the player, while being turned to the player/ground.

Question 1 : Camera Collision using sparkys DLL.

The command I'm using to detect collision is:
"SC_RayCastGroup"
Snippet of my RayCast code in the main loop.

I haven't used any variables yet, will do this when the code is fully functional.



The explanation of the command :


I'm using the SC_RayCast(Group) command also to for bullet handling, and it works flawless.

When there's an object between the player and the camera, the camera repositions but still lets parts of the object be seen.

When setting the value of
"move camera 0,sc_getcollisiondistance()+1"
to lets say, 10
"move camera 0,sc_getcollisiondistance()+10"

The camera repositions Distance * framerate wich makes the game unplayable.

I've tried using the SQRT command into a CameraDistance# variable to replace the SC_GetCollisionDistance like this :



This does not work either and gives the same result.

How can I make the camera collision work properly?



Question 2 :

I have set up a second camera :



The code I'm using to move my character around using the mouse, and the WASD keys :
(It's from a tutorial)



And in a Gosub MovePlayer (From the Sparkys DLL Example)



The camera is showing up in game at the specified coordinates on the screen, and it's showing my "character" from top view, wich is good.
However when I use the keys to walk, my camera "flips" around.
My guess is I need to somehow make this camera only follow the player, and not rotate around.

Ideas to help me out, shoot them please.

Also a side question :

I have a Limb in front of the player as weapon aim. It positions randomly to create a "real" effect for weapons not exactly shooting at where you aim.




It's working but one little problem there.
If you slice the screen in half over the heigth and width you'll have 4 "squares", the limb only randomly places in the top right squares, or are my eyes betraying me?



Thanks again for your time, I will be posting a video tonight showing my problems to make them more clear.

Also any comments to create my ideas in a different way are much appreciated.

Watch my problems in High Def on
http://www.youtube.com/watch?v=EkEG1qSIGz0&feature=youtu.be

Hi 5!
29 games
19
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 18th Mar 2012 19:34
Hi Ramon

I've had a look at this and think I can answer all your questions:


Quesiton 1:

Quote: "When there's an object between the player and the camera, the camera repositions but still lets parts of the object be seen."


Rather than using a ray cast for camera collision I use a sphere cast, as it keeps the camera away from any objects that it has collided making it easier to deal with the problem you have mentioned

Question 2:

Quote: "...when I use the keys to walk, my camera "flips" around"


If you're using the object y angle to get the angle you want your camera then this will happen due to how DBP rotates objects. Run this code (a spinning cube) and look at what happens to the object's angles.



The y angle goes from -90 to 90 degrees and the other angles flip between 0 and 180. This still visually looks the same on the screen but obviously messes with any code using just the y angle. For third and first person stuff, I normally use variables to control the angles.

Below is a demo of how I would do what you are trying to do.



Bonus Question:

Quote: "I have a Limb in front of the player as weapon aim. It positions randomly to create a "real" effect for weapons not exactly shooting at where you aim."


Your random function only returns positive values, 0 thru 5, so it terms of the limb offset this to the right (x offset) and up (y offset). If you want it to go both left and right and up and down you need to have a "equation" that give values from negative to positive, with negative values offsetting the limb to the left and down, something like:

offset = rnd(10) - 5

which will give values from -5 thru 5.

Hope this is what you were after
Ramon156
13
Years of Service
User Offline
Joined: 13th Jul 2011
Location: Netherlands
Posted: 19th Mar 2012 15:46 Edited at: 19th Mar 2012 15:49
Hi 29 games, thank you for your response.

The camera is working.



It's a bit different as your code, but it works like it should.
Mouse is used to rotate, WASD to move / strafe.

The random limb positioning works good now, I didn't know it was possible to do it like that.

RND(10) - 5
This range is from -5 to 5. I've been using RND(10)-10 myself before I asked for help *Slaps forehead*.

The camera collision is not working like it should when using your code.
It is not going through objects, but SC_SphereCastGroup seems to work better than SC_SphereSlide, is that a mistake from your side or am I doing something wrong?
To clear things up, this is the code I'm using now wich gives the best collision :



Thank you for your help.
29 games
19
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 27th Mar 2012 01:32
Glad you got your code working.

Quote: "_SphereCastGroup seems to work better than SC_SphereSlide, is that a mistake from your side or am I doing something wrong?"


No, this way my mistake and I seemed to have made the same mistake in the game I'm writing at the moment so thanks for flagging it up, I might not have spotted it otherwise.

Anyway, as I said, I'm glad you got it working.
Ramon156
13
Years of Service
User Offline
Joined: 13th Jul 2011
Location: Netherlands
Posted: 3rd Apr 2012 16:57
Thank you 29 games for your help.

On my youtube page is a video of how its currently working.

http://www.youtube.com/watch?v=EkEG1qSIGz0&feature=youtu.be



Also I'm trying to make the following and I don't want to open a new topic again.

Camera is top view , following the player.
The objects in the level that cannot be seen by the camera should hide and unhide accordingly to collision with a box attached to the player.
This is to optimize the game and make it run smoother.

Let's say my camera "view" is 200x200.
I'd make a box attached to the player that's 800x800 wich is my "fadecheck".
Everything colliding with the fadecheck box => 1 should unhide (this would be seen by the camera).

Everything colliding with the fadecheck box =< 0 should hide (Wich is not to be seen by the camera)

This is only if , hiding objects would speed up the game.


Now I've made a for-next-loop in my main loop (Wich will be put into a function later, if working correctly).
This loop will be something like


This however does not work.

The fadecheck box is following the player, objects are not hiding or unhiding (I've made about 20 boxes to test it)

There would be also a way of checking the distance from the player to each object, if there's 1000 objects there would be 1000 distance checks each frame x 60FPS = 60.000 checks each second.
Same goes for the for-next-loop, 60.000 checks per second.

How can I make this work, or is there maybe an easier way to accomplish this?

Thank you

Btw 29 games do you have a video or some screenies of your game?
Ramon156
13
Years of Service
User Offline
Joined: 13th Jul 2011
Location: Netherlands
Posted: 3rd Apr 2012 17:58 Edited at: 3rd Apr 2012 18:04


It seems that I got the idea working like this with DBPro code.
Objects hide and show according to collision with the fadebox.

Now I would only need to stranslate this into sparkys DLL code wich I will try for myself first.

I have no idea why my first pieces of code didn't work as they gave me "Object does not exist" errors.

Does it have to do with
"If object exist = 0 then exit"

Loop starts counting: 1,2,3,4
Object Number 5 does not exist
It exits the FOR loop, completes the DO loop, starts the DO loop again, comes at the FOR loop but instead of starting at 5 to check, it starts at 1 again, resulting in errors or objects not using the collision command.

Would this be the way to do it :
"If object exist = 0 then next X"

Sorry for double posting!
29 games
19
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 5th Apr 2012 01:57 Edited at: 10th Apr 2012 02:15
Personally I would change this:



To this:



The other thing I tend to do is assign variables for all the object ident numbers so I don't have to do the "If Object Exist" bit.

Edit: I somehow managed to delete the part where all the crates are added in, this has now been added


Instead of using the "num_objects" variable, I believe there is a command in one of the plug-ins that will find a free object id number for you. It works out to be the same. What you will notice, is that it's very easy to change the number of crates (just change the value for "number_of_crates" variable) and to add new objects in. So if you added in:



afte the block of code that generates the crates, then you've added a whole bunch more ojects without having to worry if object numbers have already been used.

Quote: "There would be also a way of checking the distance from the player to each object, if there's 1000 objects there would be 1000 distance checks each frame x 60FPS = 60.000 checks each second.
Same goes for the for-next-loop, 60.000 checks per second"


You could restrict the number of checks to, say, every fifth or tenth loop. When you think about it at 60 fps, a frame is only on screen for about 17 milliseconds so the player probably would notice anything. If you did a check every 5th loop, then you'd reduce the number of checks a second from 60,000 to 12,000 per second. I reckon you could do the check once every tenth of a second and no one would notice. However, objects would be on screen for longer so you'd have to play around with the optimim amount of checks per second. I tend to find that the number of polys / models on screen seems to have a higher impact than number of collision checks but this is something you need to play around with.

Quote: "Btw 29 games do you have a video or some screenies of your game?"


Not yet.
Ramon156
13
Years of Service
User Offline
Joined: 13th Jul 2011
Location: Netherlands
Posted: 10th Apr 2012 01:24
Ok I know how to implement this into my projects.
But I just don't understand how it works.

Does "num_objects = 0" keep increasing every time you make an object?

When I print the variable to the screen it returns 0 , even after creating 4 "For next loops" who each make 1000 boxes.

Is this something DBPro handles in a dark back alley so I don't have to worry about it?
29 games
19
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 10th Apr 2012 02:22 Edited at: 10th Apr 2012 02:23
Hi, I somehow managed to screw up one of the code snippets I posted. I've edited the code (the third one) and now it creates some white cubes (crates) that will turn red when you drive the green box into them.

Yes, the "num_objects" variable is being incremented everytime I make an object. Each object then has its own id in the form of a variable that has the current value of "num_object" written to it. Hopefully, this should now be clearer from the edited code snippet.

It's just a method I use for object management and stops me from accidentally using the same object number more than once. When you have all your object id number in variables, it makes them easier to reference in your code. I also find this method handy if I have to delete objects, say when deleting a level and loading a new level in I can just use a simple FOR...TO...NEXT loop to delete everything. Ie:

For i = 1 to num_objects
delete object i
next i

and I'll know the object exists without having to check first.

People do different things. The exact method you'll end up using may depend on how many different types of object you are loading. The FIND FREE OBJECT command is part of Ian M's Matrix1Utils plugins collection, which can be found here:

http://forum.thegamecreators.com/?m=forum_view&t=85209&b=18

This way you could do something like (you'll need the plugin to run the code but have a look at the section where the objects are being loaded in):



And if you wanted to add some different objects in you would just add in:



at any point before the start of the DO...LOOP. The reason I don't use the FIND FREE OBJECT command is that I've only recently downloaded and intalled the plugin, that and I like to work things out for myself using the native DBP command set (I find this is a good way to learn stuff).

What you need to do is work out how you want to manage all your object id numbers, and the id numbers for the rest of the media you'll be loading in. It's quite scary how quickly it all becomes unmanagable if you haven't thought about it at an early stage.
Ramon156
13
Years of Service
User Offline
Joined: 13th Jul 2011
Location: Netherlands
Posted: 10th Apr 2012 14:10
Hi 29 Games!
I've made a typo in my code. Used "numer" instead of "number"!
That was the reason for not having it printed on my screen. Didn't gave me an error but appearently every variable thats typed wrong just returns 0!


I have the same reason for skipping plugins, except for sparkys but that's more due to a lack of math knowledge.
I've been using DBPro in a good way since feb this year, learning quickly but also think in a too difficult kind of way to make functions and so on.

That plugin(page) looks good though.

Is there a reason why you're using only an array to store the ID?



I use this same method for the NPCS spawning in my other post (Type Arrays)
And the part where I look for a new waypoint fails dramatically, maybe due to type arrays.

Thank you for help and making my object creation allot easier.
29 games
19
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 10th Apr 2012 21:09
The reason I only used a basic array on the examples was that there was no need to store any other information about the object other than its id, so setting up a type might be a bit of an overkill.

If there are other stats associated with the object, such as a npc where you may have health, speed, strength etc, then arrays are the way to go. However, simillar to the issue you raised, I currently have the way point array seperate from the npc array / type as I have a single dimension array for the npc, associated with a UDT and a multi-dimensional array for the way points, and I don't know enough about UDTs to be able to hook them together (if it's at all possible).

Don't feel bad about using Sparky's. I've done a lot of maths collision in DBC and the maths is difficult and the end result is slow. It's a brilliant learning exercise but the end result is not really worth the hassle.

I believe that Ian M's matrix utility plugin in very useful and I'll be having a look at it. More pluggins can be found on a sticky at the top of the program announcement board of you're interested, there's a 2D one that's supposed to be quite good.

Anyway, glad you're moving on with your game.
RonsWare
14
Years of Service
User Offline
Joined: 5th Sep 2010
Location: Netherlands
Posted: 12th Apr 2012 08:57
Ga zo door ziet er goed uit.

Programming is learning

Login to post a reply

Server time is: 2024-11-23 20:19:35
Your offset time is: 2024-11-23 20:19:35