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 / Top Down Shooter help- current problem: aiming.

Author
Message
Zaibatsu
18
Years of Service
User Offline
Joined: 1st May 2006
Location: Lost in Thought
Posted: 9th Jan 2009 04:54
Well, in a period of less than a year, I gave up learning Dark Basic Pro, started learning and quit C++ twice, started and quit C#, and now I'm back to Dark Basic Pro, and here I shall remain.

Anyways, I started a top down shooter game, kind of like Crimsonland. So far, I have a green sphere that serves as the player, and a red hexagonal prism that serves as the enemy. The player can be controlled by the WASD keys, and the enemy will follow you wherever you go.

I've also got the mouse replaced by a crosshair.



My current source code is:



What I'm trying to do now is get the player to rotate to face the mouse so I can get shooting implemented (which I will also probably need help with). I tried using the point object command and telling the sphere to aim at the mouses coordinates, but that messed up the moving commands because the objects left and right would change as it swiveled.

Thank you in advance for any help I receive.

All the media and the project file is enclosed in an attached .zip file. If for some odd reason somebody wants to swipe a sphere and a hexagonal prism model for their own use, go ahead. If any other beginner wants to use my code as a reference or base for their own, go ahead; I'm planning on releasing the game and source for free when it's done anyways.

Attachments

Login to view attachments
AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 9th Jan 2009 12:27
The problem you're having with pointing the object at the mouse coordinates is that their 2D coordinates, while the command wants a 3D coordinate. So you're going to want to convert the mouse coordinates to 3D coordinates first, then point the object at them.

Tell me if this works for you:




Pillarofire
20
Years of Service
User Offline
Joined: 31st Dec 2003
Location: Good Question, <looks around.>
Posted: 9th Jan 2009 14:13 Edited at: 9th Jan 2009 14:14
AndrewT is on the right track. This however will produce some awkward results being that your pick vector is always the same length (1000.0) so you will be calculating a point as if it were on the surface of a sphere centered on the camera.

If this does not work for you, you could also cheat and make a plain on which your player and other character are walking on, and then do a PICK OBJECT(). Then use the same concept of adding the vector to the camera and so forth.

EDIT:fixed a typo.
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 9th Jan 2009 19:16 Edited at: 9th Jan 2009 19:19
Here's how Id do it...

First of all, establish what you want to do in 2D. You need to get the angle between a player and the mouse, and rotate them to that angle. The atanfull command can be used pretty easily to get this information provided you have two positions.

Here's a demo of it in 2D...




So now the only problem is getting the player's two-dimensional coordinate on the screen, from their 3D position in the virtual world.

This isn't all that hard either. There's always the OBJECT SCREEN X/Y commands. But those can be inaccurate when the camera isn't directly above the player, and the camera's field of view comes into play.

So the easier option would be to go the other route and get the mouse's 3D location. This can be done with the PICK SCREEN command, which converts 2D coordinates to 3D.



That should work. I had to set the atanfull's output to negative in the 2D version because for some reason it was rotating oppositely, not sure why but not too hard of a fix. The 3D version works normally though. The only difficulty is you need to set the pick vector distance to be the distance the camera is from the ground plain. This is where you might want to look into the pick object command, to get this information.

Also, its not too smart to use a sphere for your player when you're trying to see it rotate properly. Id recommend using a cube or a stretched box, and to be really sure I would add a sphere limb or some sort of identifier on the front of the player so you knew it wasn't facing backwards, as you can't really tell that with simple primitives.

Zaibatsu
18
Years of Service
User Offline
Joined: 1st May 2006
Location: Lost in Thought
Posted: 10th Jan 2009 00:18 Edited at: 10th Jan 2009 00:33
@ AndrewT-

Yeah, that works, but the problem again is that the players left and right changes as it rotates, but I thought of a fix for that. I'll make the WASD keys control a VERY small cube inside of the player model, and have the mouse rotate the player model so the cubes left and right never change.

Thank you.

I'll update with the new source code when I'm done editing it.


EDIT: Ok, I'm noticing some issues with it now. Every few second, it rotates vertically like the mouse is either above or below it. It can't do this or the player won't be able to shoot anything, which makes me think I need to figure out a way to use the rotate object command when the mouse moves to insure that it only rotates on the axis I want it to.

Anyways, I went ahead and attached the player to a cube inside of it so it can rotate and not mess up the controls.

New Source:



RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 10th Jan 2009 17:26
Thanks for... ackowledging I helped you at all.

First of all, the issue you're having with the player model rotating weirdly on the z axis, is because you're using the POINT OBJECT command. It has to do with Eular angles and how the object's rotation is calculated. Thats why I showed you how to do what you're trying to do by calculating an angle and rotating the object on the y axis. This ensures the object will only rotate on the y axis, and never give weird results when the mouse get's closer to the player. So Id recommend switching to this method.


I didnt understand the problem before but now I do, although I dont actually see it as a problem as I would expect to strafe around my reticle instead of having the reticle's position change when I strafe to keep a sideways movement.

Anyways, there is again two ways you can accomplish what you want to do. You can either add an offset value to the player that shifts them to face a point to the right or left of the reticle, moves them, and then points them to the actual reticle, OR you can adjust the reticle's position as the user strafes to continuously be infront of the player.

Zaibatsu
18
Years of Service
User Offline
Joined: 1st May 2006
Location: Lost in Thought
Posted: 10th Jan 2009 22:56
Quote: "I didnt understand the problem before but now I do, although I dont actually see it as a problem as I would expect to strafe around my reticle instead of having the reticle's position change when I strafe to keep a sideways movement."



I'm not sure what you mean by that, which makes me think maybe you don't quite understand what I meant. I want the game to control in the same manner as the game Crimsonland. If you're not familiar with the game, you can download the trial version here.

Login to post a reply

Server time is: 2024-11-24 14:44:00
Your offset time is: 2024-11-24 14:44:00