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 / 3rd Person Camera View

Author
Message
Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 12th Aug 2007 10:49 Edited at: 12th Aug 2007 10:52
Firstly, thanks for taking the time to read this.

Well, i'm working on a 3rd person game (fairly basic), and i've got the camera working fine, but what i'm trying to achive is when the user moves the mouse up and down, the camera moves up and down. Here's the code i'm using, what i've gotten it to do is when you move the mouse, the camera moves sideways, but I want it to move up and down.

Code i'm using :


Oh, and one other thing, saves making another thread, and it's fairly simple... I hope.

Upon collision with another object, I want the player to stop moving. I've tryed various things, but none of them work properly, for example, below, I tried some code to make the user move backwards whenever they collided with the object, but the user moved back 1 pixel, and then just kept on moving through the table (Object 65)

Code i'm using:



Thanks for any help you can give.


[center]
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 12th Aug 2007 12:36 Edited at: 12th Aug 2007 12:41
Q1) if you want the camera to move "up/down" you need to rotate on the x axis, not y.
oh, and the code you offered re: the camera is moving an object, not the camera...

Q2) consider the following pseudo-code:



you'll hear a few better methods on how to handle collision. the built-in collision in DBPro is far from perfect and the method you're showing in your code snippet is relying on perfect collision. long story short is you'll have to handle some things manually. in the example provided, i'm recording a known safe point (where there was no collision). collision causes it to go to the safe point vs "1" unit backward. make sense?

look at other collision code examples in the code base for help. there's good knowledge there (by people with much more experience than me).

btw, get used to using real numbers when parameters call for reals. moving "1" vs "1.0" will cause you some grief, too.


good luck to you!

Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 12th Aug 2007 12:50
1)
I have a hard time figuring out how this line:
YROTATE OBJECT 10,WRAPVALUE(OBJECT ANGLE Y(10)+MOUSEMOVEX())
would in any way affect the camera since it just rotates object 10

but you could try this lines :
camx=camx+wrapvalue(mousemovey())
XROTATE camera camx

this won't work if you have a point camera command in place

2)

you could keep track of the old player position when there's no hit and use the old position when hitting::

IF OBJECT HIT(10,65)=0
olsplrxpos=plrxpos:oldplrypos=plrypos:oldplrzpos=plrzpos
endif

IF OBJECT HIT(10,65) THEN POSITION OBJECT 10,oldplrxpos,oldplrypos,oldplrzpos


here s a basic example of code i use for the FPS camera
maybe you can get some ideas.

Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 12th Aug 2007 14:12
Thanks to both of you for the quick replies.

Quote: "Q1) if you want the camera to move "up/down" you need to rotate on the x axis, not y.
oh, and the code you offered re: the camera is moving an object, not the camera..."


Man i'm an idiot, thanks for pointing that out.

As for the collision issues, I tried both methods, and neither worked, the player just kept on walking through the object.

Scorpyo:

The camera code doesn't work because I have a POINT CAMERA command in place, but without that command, the player doesn't stay centered on the screen. Using the LOCK OBJECT ON command didn't work either.

But again, thanks to both of you.


[center]
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 12th Aug 2007 20:25
quote
-I have a POINT CAMERA command in place-

in that case link mousemovey() to a "height" variable and add it to the point camera y height:

like:
campointh=campointh+mousemovey()
point camera plrxpos,plrypos+campointh,plrzpos
Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 13th Aug 2007 10:16
Hmm, no luck still. Current code i'm using below.



It's contained within a DO-LOOP by the way.


[center]
PowerSoft
20
Years of Service
User Offline
Joined: 10th Oct 2004
Location: United Kingdom
Posted: 13th Aug 2007 11:30 Edited at: 13th Aug 2007 11:34



This is the code I am using in my 3rd person game. Simply Pass the camera number (pass 0 for default camera) and the object number for the player. This will then position the camera 10 units behind the object and 10 units above the object. Finally it will then point the camera at the object.

[edit]
To change the X/Z and Y offsets simply change the value in the constants,

The Innuendo's, 4 Piece Indie Rock Band
http://theinnuendos.tk:::http://myspace.com/theinnuendosrock
Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 13th Aug 2007 12:21
Thanks for that, but i'm looking for code that moves the camera up and down. I've got the actual camera working fine. Thanks for your help though.


[center]
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 13th Aug 2007 12:49
this is redundant if you operate with an adjust value to point camera:
camx=camx+wrapvalue(mousemovey())
XROTATE camera camx

this works :


try this trick as from the example:

mymousey=mousemovey()
if mymousey>0 then campointh=campointh+3
if mymousey<0 then campointh=campointh-3
Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 13th Aug 2007 14:48
Woah, that got messy.

I tried to implement that camera code into my current code, but got nothing, the camera wouldn't move up or down, and the game had an FPS view.

Current code for the whole camera system below, what exactly would I need to add to just move the camera up and down, with nothing else?



Thanks!


[center]
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 13th Aug 2007 18:19
PowerSoft
20
Years of Service
User Offline
Joined: 10th Oct 2004
Location: United Kingdom
Posted: 13th Aug 2007 19:36
Moves the camera up and down? As in position? or where it's looking?

Position simply change the Y value in POSITION CAMERA
Where it's looking just XRotate the camera.

The Innuendo's, 4 Piece Indie Rock Band
http://theinnuendos.tk:::http://myspace.com/theinnuendosrock
Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 14th Aug 2007 10:58
Quote: "Moves the camera up and down? As in position? or where it's looking?"


As in so you can see what's above you and below you, so, as in where it's looking.

@Scorpyo: Thanks for that, but the problem is that when I use the WASD keys to move the player around, the camera does a whole loop around the player, kind of hard to explain what is it, but I think that it's because the player isn't locked onto the screen. Don't trust me on that one though. And also, when you move your mouse up and down, the camera only moves up/down a tiny bit, then stops.


[center]
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 14th Aug 2007 13:08
how does this work for you?
Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 14th Aug 2007 14:16
Works well, but how would I implement that into my code without drawing the matrix, the cone etc.., just the camera coding?


[center]
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 14th Aug 2007 20:02 Edited at: 14th Aug 2007 20:04
remove makeplayer and makeobjects to take away the sphere and the cubes and put your own stuff

i made up and down camera movement with mousemovey() and leftmouse click to avoid mouse cursor wandering, but you can remove the if...endif if you don't like it like that.



edit: I forgot to tell you that all variables in functions must be made global in order to work
Aralox
17
Years of Service
User Offline
Joined: 16th Jan 2007
Location: Melbourne
Posted: 15th Aug 2007 14:26
Just thought id put up a link to RUCCUS's legendary camera code here.
http://forum.thegamecreators.com/?m=forum_view&t=89100&b=19

Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 16th Aug 2007 11:26
Oh man, that's nice, worked perfectly. Little bit of tweaking and it'll be awesome!

Thanks to Scorpyo, Virtual Nomad, Powersoft and Aralox for the help, it's much appreciated.

Not to pester, but how would I get the simple collision working when the player collides with another object, and stops moving. Tracking the player's position, and then, upon collision, moving it back to the previous position didn't work.

Thanks.


[center]
Aralox
17
Years of Service
User Offline
Joined: 16th Jan 2007
Location: Melbourne
Posted: 16th Aug 2007 11:40
Your most welcome

Quote: "Tracking the player's position, and then, upon collision, moving it back to the previous position didn't work.
"

whoa you work really hard for your code. i think there is a native dbp command 'camera collision' or something. look it up in the help section.

Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 17th Aug 2007 11:42
I don't want the camera to collide, I need the player object to collide.


[center]
Aralox
17
Years of Service
User Offline
Joined: 16th Jan 2007
Location: Melbourne
Posted: 17th Aug 2007 13:10
use sparky's dll

Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 18th Aug 2007 06:09
Looking through all the documentation for that, that just detects collisions. I can detect the collision fine, I just can't get the player to stop upon collision.


[center]
Aralox
17
Years of Service
User Offline
Joined: 16th Jan 2007
Location: Melbourne
Posted: 18th Aug 2007 08:25
interesting. i never thought about that.

Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 18th Aug 2007 12:55
Can I sense a hint of sarcasm in that?


[center]
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 19th Aug 2007 00:15
what are you using Veron? object hit?
Aralox
17
Years of Service
User Offline
Joined: 16th Jan 2007
Location: Melbourne
Posted: 19th Aug 2007 03:08
nah no sarcasm. i just never thought that. sets me on a thinking spiral - detect collision>stop, but how would you get away? you know what you could use? you could test the angle of the normal directly in front of you, then if youre facing towards that angle(use some trig here i think) then youre forced to stop, and if youre not facing it, move away, but stop when you back up.

Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 19th Aug 2007 03:39
Quote: "what are you using Veron? object hit?"


Yes, i'm using OBJECT HIT.

Quote: "you could test the angle of the normal directly in front of you, then if youre facing towards that angle(use some trig here i think) then youre forced to stop, and if youre not facing it, move away, but stop when you back up."


Ooh, that'd be pretty tough, but, yeah trig would do it.


[center]
Aralox
17
Years of Service
User Offline
Joined: 16th Jan 2007
Location: Melbourne
Posted: 19th Aug 2007 09:43
You know what? i was writing up some collision code the other day, trying to work out ramp collision with native dbp code, and i came up with some pretty good looking code. on paper at least. im not sure where i put it though.

Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 19th Aug 2007 14:37
Ramp collision? I think I saw some good 2D ramp collision code a few weeks ago, i'll dig through my "Projects" folder and see if I can find it for you.


[center]
Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 22nd Aug 2007 11:44
*Bump* Any help with the collision?


[center]
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 22nd Aug 2007 14:13
well I have several collision code examples but I use intersect object:

here's one basic (doesn't prevent player sides through objects)



more precise ( does check players sides)



P.S. Soon the board will cringe at these typical Scorpyo's green painted matrixes
Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 22nd Aug 2007 14:25
That's cool, thanks. How would I implement the more precise one into my code? I tried just removing the GOSUB statements that draw the matrix etc..., but to no avail.

Thanks again.


[center]
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 22nd Aug 2007 15:37 Edited at: 22nd Aug 2007 15:39
Basicaly it's these 2 routines that should be called from the main loop


BUT:

here you must state the from-to numbers of your objects to collide with:

for n=100 to 120

AND

you are using move object therefore i guess you are not storing your player x,z position in x# and z# so you should put this at the beginning of the checkdistance:

x#=object position x(yourplayerobjectnumber)
z#=object position z(yourplayerobjectnumber)

AND

adjust the intersect value according to your player radius

if collcheck1#< radius
if collcheck2#< radius
Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 23rd Aug 2007 04:46
Quote: "here you must state the from-to numbers of your objects to collide with:"


So there you just place the 2 numbers of the objects you want to collide?

Quote: "adjust the intersect value according to your player radius"


How do I find out the player's radius? I'm scaling the player object like this : SCALE OBJECT 10,30,30,30

So would 30 be the radius?


[center]
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 23rd Aug 2007 12:00
you're not studying the code at all:

1)
It's a range
for n=100 to 120 means from object ID number 100 till object ID number 120, therefore i'm checking the 21 cubes (100 to 120) objects from first to last.
Put you object range there, if the ID numbers are not contiguous do this:


2)
look into these commands or experiment with some radius values till you get it right

Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 23rd Aug 2007 13:14
Ok, spent a while experimenting with the radius, and figured it out. My current code is this:



But as soon as I run the game (F5), it opens up and closes straight away. What's with the problem there? If I remove the collision code, it works fine.


[center]
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 23rd Aug 2007 17:37 Edited at: 23rd Aug 2007 17:40
those are routines that must stay out of the do -loop



and replace the collchecks values with radius

if collcheck1#<radius
if collcheck2#<radius
Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 24th Aug 2007 11:05 Edited at: 24th Aug 2007 11:16
So just replace where it says collcheck1# and collcheck2# with the radius, or replace the variable radius with the radius?

Replacing the variable radius with 30 did nothing.

EDIT: I've been tweaking, and here's my code. Collision works fine I think, but I can't move anywhere, because it stops you moving if your colliding with an object, but the ground is an object, which i'm always colliding with. How do I exclude collision from certain objects?



^^^^^ Current code BTW. ^^^^^


[center]
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 24th Aug 2007 14:35
try this:



by the way objnum was set to 10 and it should be 0

you forgot to put radius instead of 16 in the first set of collision check

please be more precise if you want help to work, you are working by paste and copy without analysing the code.
Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 24th Aug 2007 14:57
Nope, no change. Whenever you press the movement keys (W,A,S,D), you move forward maybe 1-2 pixels (in a jerky motion) while the key is held down, and when you release the key, it moves back to it's original position.


[center]
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 24th Aug 2007 15:14
of course, object 10 is the player, i didn't notice
that , it must be excluded from the checkdistance in the for-to

change to for n=11 to 100

the object range in the for-to is only the objects you want the player to check collision with
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 24th Aug 2007 15:31 Edited at: 24th Aug 2007 15:31
Tihs pic may help you to understand

Attachments

Login to view attachments
Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 24th Aug 2007 16:07
Hmm, still the same problem.

Thanks for that picture, it helps a lot!


[center]
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 25th Aug 2007 00:03
I almost had to rebuild it
My routines were based on position object, not move object
I have put fake objects, replace with your own


Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 25th Aug 2007 04:12
The code compiles fine, but when I try to press the "W" key to get it to move forward, I get the error: Runtime Error 7008 - Object Does not exist at line 564.

I thought these lines
were the problem, so I changed the ">0" part to ">11" Then I ran the code, and I could press "W", and the player would move upwards, but wouldn't collide with anything.


[center]
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 25th Aug 2007 13:18
well, good call but if you want to put a minimum to objnum it shold be 10 because the first object to check is just 11 in the example therefore : if objnum>10 etc..

Dude , it works perfectly either way here.
are you sure you copied the code properly?



I'll attach the .dba and .dbpro too, let's see

Attachments

Login to view attachments
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 25th Aug 2007 13:25
and the exe as well

Attachments

Login to view attachments
Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 25th Aug 2007 14:23
Ok, now it's trying to tell me that Object 10 doesn't exist, which it certainly does. But, I think the problem is this: Look at the code i'm using.



Now, at the top, it says this:



That's putting the collx# value AND the object position value (x#) into the one variable (x#), so that's what's wrong... I think.

Obviously I could just change the collx# = x# line to collx# = cox# or something like that, to separate the values, but then I don't know what x# values in the code after that to change to cox#.


[center]
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 25th Aug 2007 20:21
[quote]
Ok, now it's trying to tell me that Object 10 doesn't exist, which it certainly does. But, I think the problem is this: Look at the code i'm using.

In that code you put there's no object 10 created or loaded
where have these lines at the beginning gone?

make object sphere 10,30
gosub makeobjects


collx#=x#
collz#=z#

this puts the object positions x and z in collx# and collz# at each loop and those are used to know what x and z were before the collision in order to put the player back there when


I want to know if the .dba or the exe that I provided work
Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 26th Aug 2007 04:27 Edited at: 26th Aug 2007 04:30
Ah, sorry, yes, they [the .dba and the .exe] worked fine. But it doesn't matter, read on.

Quote: "where have these lines at the beginning gone?"

I had already loaded the played object further up in the code, the code i've been posting isn't all my code, there's about 600 lines before that which handle loading the objects and more.

At last I got it. I just sat down this morning and re-wrote most of the code, based on what I know, and it worked. Upon collision with something, the player stops.

Scorpyo, I can't thank you enough mate, this has gone on for so long. Have a beer on me!

The code I used was this:



The only problem (yes, another one) is that the camera doesn't follow the player, and I think that's because i'm changing the camera positioning and pointing in the REPEAT-UNTIL loop.


[center]

Login to post a reply

Server time is: 2024-11-25 15:32:33
Your offset time is: 2024-11-25 15:32:33