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 / Help! Isometric 3D Character Movement with Mouse

Author
Message
GuruSY
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location:
Posted: 9th Mar 2004 08:34
I'm really in a bind. Since I am on spring break I have decided to finally get started on an isometric 3D game engine. But I can't get my character to move where my mouse is!

Here is my problem:

1. I load a world plane which is just a flat rectangle that will eventually be textured with grass. I set a fixed camera to look down on it at a slight angle.

2. I load my temporary character who I want to move.

3. I want him to go where I click my mouse. But I want him to stay on the world plane (not go above it or below it).

I have looked at other posts and in the code base, but nothing I do seems to accomplish what I want. Below I describe what I'm currently trying to do, but if you read my problem above and have a better way, I would love to see it.

In the attached code I try and use the pick screen command to translate the mouse cords to 3D cords, but the distance constant is giving me problems. The character will move where I click the mouse, but not all the way to the top of the screen or to the left and right of the screen. When I increase the distance constant, the character doesn't go where I click. When I decrease it, I decrease the radius that the character will move. I want the character to move anywhere on the plane where I click.

The object files that I am using are just a plane textured with grass for mygrass4.x and a simple character model for dude.x.
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 9th Mar 2004 14:13
Thats because you are using a constant value as the distance. Obviously the distance between: (a) the camera; and (b) the plane which represents the world plane CHANGES depending on the angle on the screen where your mouse pointer is.

I'm going to have a fiddle about with your code and try to produce some amended code which does what I think you want. Hang on.

Philip

What do you mean, bears aren't supposed to wear hats and a tie? P1.3ghz / 384 megs / GeForce MX 5200 128meg / WinXP home
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 9th Mar 2004 15:50
... and here you go (see the attached yellow source box). The code is DBPro code and I've tested it - it works perfectly. Click anywhere on the matrix and the red cube will be repositioned there.

I think I'll add this to the codebase and the code snippets

Cheerio

Philip

What do you mean, bears aren't supposed to wear hats and a tie? P1.3ghz / 384 megs / GeForce MX 5200 128meg / WinXP home
GuruSY
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location:
Posted: 9th Mar 2004 18:11
Wow! Thanks for taking the time to look at my code.

But I do have a problem...

if you change the camera to a slight angle:
position camera 0, 0, 100, -15

Then the code gives me the same problem that I had before.

Thanks again!
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 9th Mar 2004 18:54
Yes of course it does.

Thats because my code is premised on the basis that the camera is looking right down the y axis and this forms the adjacent side of a right angled triangle. The hypotenuse of the triangle is the imaginary line between the position of the camera to the point on the matrix which the mouse cursor is over.

Therefore, once you change the camera's angle this right angled triangle instantly ceases to exist. Also, you didn't say you wanted to change the camera's angle (which is not really the sort of thing you see in an isometric engine anyway) so I worked on the basis above.

Anyway, if you want to be able to move the camera without changing its viewing angle then the attached code does the trick for you. Move the camera with WASD keys. Mouseclick to move the object.

I'll put this code on the code snippets forum and into codebase as well.

Philip

What do you mean, bears aren't supposed to wear hats and a tie? P1.3ghz / 384 megs / GeForce MX 5200 128meg / WinXP home
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 9th Mar 2004 19:00
Actually sorry GuruSY for the slightly peeved tone of my last post.

Sometimes I feel like I go to all the trouble of writing REM statements in my "helpful" code but nobody reads them!!

Cheers

Philip

What do you mean, bears aren't supposed to wear hats and a tie? P1.3ghz / 384 megs / GeForce MX 5200 128meg / WinXP home
zircher
21
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 9th Mar 2004 19:34
For a bear, I think you have really good manners. The average big brown bear would have batted him around like a soccer ball until the bear got bored and either ate him or walked away.
--
TAZ

code master
20
Years of Service
User Offline
Joined: 4th Dec 2003
Location: Illinois
Posted: 9th Mar 2004 22:04
Philip please give me the mouse code for db clasic if yah can do that?!

codemaster
GuruSY
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location:
Posted: 10th Mar 2004 01:35
No, I read your REM statements, I was just pointing that out because I don't want a top-down camera, I want to look at it at a slight angle. The camera position is to be fixed, but not top down.

Your code is actually the best I have seen in terms of comments. I have looked at other code, but I cannot follow what they are doing in order to adapt it to my situation. It is a math problem, but I am rusty at my linear algebra.

Thanks for the help so far though!
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 10th Mar 2004 16:32 Edited at: 10th Mar 2004 16:34
@GuruSY

This might be your birthday! As you and Red_Eye both asked for the ability to pitch the camera up and down, I've revised my code to include that. For good measure I've also included some code to spin the camera's lens and also you can now move the camera up and down on the Y axis. So basically it now does everything anybody could ever ask for in an isometric style game. I've also significantly expanded the rem statements - I hope you find that helpful.

I'll put the code into the code snippets board and into the codebase.

Two remaining issues:

1. the first time you use the pitch or roll keys the camera will "jump". This is a known DBPro bug I'm afraid - first reported by Spooky. Lee says he will fix it in U6

2. if the mouse cursor is "above" plane of the matrix then the red cube will vanish into infinity. If you want to stop this just include some if statements around the position object 2 command in the function so that object 2 will not be positioned if the X and Z values are greater than the size of the matrix (-500 to +500)

@Zircher

Thanks! Moreover, its odd you should mention this because I was discussing just the same issue with a big brown Grizzly friend of mine the other day. He's not so used to humans as I am. In fact, you might say he's not really as cultured. He was saying to me that being around humans must be great because if you get angry you can claw them and if you get hungry you can just kill one and consume it.

I had to explain to the chap that this kind of behaviour is considered distinctly anti-social by humans. It'd put a significant dent in one's social life. Besides, I prefer jam sandwiches and lunch hampers.

@Codemaster

I would if I could but I only have DBPro. I don't have DBC. My code is heavily commented so it should be very straightforward for one of the DBC whizzes to convert it. I'd suggest you put a post into the DBC forums with a link to this thread asking someone to put together a conversion for you. JessT may be your man for this - he's that forum's chief Saint.

And, with that, my work here is done. I'm off to continue learning 3d Canvas Pro.

Philip

What do you mean, bears aren't supposed to wear hats and a tie? P1.3ghz / 384 megs / GeForce MX 5200 128meg / WinXP home
GuruSY
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location:
Posted: 10th Mar 2004 23:59
Muchos Gracias Senor! That is exactly what I was looking for. It is probably what alot of people are looking for as well. Your comments are excellent, and I can actually follow what you are doing. Thanks for taking the time to help a newb out!
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 11th Mar 2004 15:52
Its a pleasure. Any act of kindness is repaid by an act of kindness so please do help out other forum users when they have a question you can answer.

Cheers

Philip

What do you mean, bears aren't supposed to wear hats and a tie? P1.3ghz / 384 megs / GeForce MX 5200 128meg / WinXP home
Peregrin
20
Years of Service
User Offline
Joined: 13th Mar 2004
Location:
Posted: 15th Mar 2004 14:22
I'm sorry, but this look a bit complicated to me... Wouldn't it be simpler to position the camera right above the matrix (moving it around with arrow keys), looking down, and position a pointer at ground height, and move this pointer according to mouse moves ? Then click and position the "dude" at pointer position. We could even define "screen borders limits" by preventing the pointer to move away too far from the center, just below the camera.
Oh well... Nevermind, just a thought. ^_^'
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 15th Mar 2004 15:31
Yes, that would be simpler. But it would also be much more limited. The final code I posted above works correctly in all 3 dimensions regardless of what angle in all those 3 dimensions the camera happens to have. What you propose only works in 2 dimensions and to work properly without any further maths the camera you propose would need to be fixed at a preset angle viewing towards the ground.

Its really horses for courses. GuruSY seemed to be calling for full 3d functionality. If you want 2d, then your solution might be simpler to implement (although not necessarily faster to calculate).

Philip

What do you mean, bears aren't supposed to wear hats and a tie? P1.3ghz / 384 megs / GeForce MX 5200 128meg / WinXP home

Login to post a reply

Server time is: 2024-09-22 00:34:24
Your offset time is: 2024-09-22 00:34:24