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 / Setting the correct angle to move an object towards and past a coordinate?

Author
Message
Izzy545
20
Years of Service
User Offline
Joined: 18th Feb 2004
Location:
Posted: 4th May 2009 07:17
Hi everyone, I'm currently working on a 2D shooter, WIP Post, and I'm working on some bullet AI to make it harder.

The issue I've been having is I want bullets to shoot towards the players current position as of when the bullet is fired, and then move in that angle until off the screen.

I'm having trouble figuring out the code to make my 3D plains do that. I figure I'll probably have to use newxvalue and newyvalue (those are the left and right, and up and down angles on my screen, respectively) but I just can't figure out the maths involved.

Any ideas?

bobbel
15
Years of Service
User Offline
Joined: 5th Jan 2009
Location: In my DBPro case xD
Posted: 4th May 2009 08:27
you were using plains, in 3d with 2d textures, wasn't it?

can;t you just when you shoot the bullet

point object PlainId, PlayerPositionX, PlainPositionY (for keeping it straight, you can also use PlayerPosY i think), PlayerPosZ

and then just move it like a normal bullet and delete it when off screen?

(\__/)
(O.o )
(> < ) This is Bunny. Copy Bunny into your signature to help him on his way to world domination!
Izzy545
20
Years of Service
User Offline
Joined: 18th Feb 2004
Location:
Posted: 4th May 2009 08:56
Yea, that's what I originally tried, but the way I have it set up, the plain goes up on its side and it's no longer top down.

Perhaps I should have made the camera and objects set up differently so y was still up (towards the camera) and down. Instead, the way it's set up, decreasing z moves it up (towards the camera) and x, y are on the screen as if it was 2D x and y, if that makes sense.

bobbel
15
Years of Service
User Offline
Joined: 5th Jan 2009
Location: In my DBPro case xD
Posted: 4th May 2009 10:20
what you maybe can do is save the x, y angles, point the object at player, then save the z angle, and then rotate the object using the prviuosly saved x and y angles and the saved z angle

(\__/)
(O.o )
(> < ) This is Bunny. Copy Bunny into your signature to help him on his way to world domination!
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 4th May 2009 16:28
After you use the point object command, just do an XROTATE OBJECT Object,90 or whatever you need to do to make it flat again.

If that doesn't work, ATANFULL is a command that isn't too confusing. It will give you the angle between the player and the target, so you can just YROTATE the object and it will point in the right direction.



Dragon Knight
17
Years of Service
User Offline
Joined: 10th Jan 2007
Location: Newcastle
Posted: 5th May 2009 15:12
no no no no.... don't bother with all this confusion.

Have the bullets velocity stored in an array. X AND Y velocity

Then use Sin and Cos to work out where it will move

This way the object can still be facing the camera without you having to rotate it.. position rotate it back and so on...

two ways off getting the angle... you can use the point object command then use object angle X() <-- X is just an example. Then set it back

Or you can use what i use,
Example code taken of DBP itself


or mine:


Helpful Hints:
Sin and cos are commonly used to get a new position

e.g.
Full Code:


Now I havn't tested it but i'm pretty sure that's right.. or you may have to fiddle about with it. I hope it helps though as i've spent the last 5 minutes of my free time writing it lol...

Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 6th May 2009 05:34
Hmmm....

Maybe instead of:

Quote: "point object PlainId, PlayerPositionX, PlainPositionY, PlayerPositionZ"


you could try:

point object PlainId, PlayerPositionX, PlayerPositionY, PlainPositionZ

If I'm getting your logic here.

<-- Spell based team dueling game!
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 6th May 2009 08:33 Edited at: 6th May 2009 08:34
Quote: "you could try:

point object PlainId, PlayerPositionX, PlayerPositionY, PlainPositionZ"


No, don't do that. That will only point the plane down the X axis.

I think something similar to what BMacZero suggested is best.

You should point the plane at the player, save the X and Y angles, and then clear the rotation on it:



And then, whenever you need to move it, just rotate the plane using the save angles and then use the move object command:



Edit: Oh, I forgot. After you move the plane, don't forget to clear the rotation on it like before.
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 6th May 2009 15:37 Edited at: 6th May 2009 16:19
@Kira: My method seems to work:



Or perhaps I misunderstand the problem. Is he just trying to point the plain at the camera and move it in another direction?

<-- Spell based team dueling game!
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 7th May 2009 01:20 Edited at: 7th May 2009 01:22
Sixty Squares: No, I think you've got the problem, it's just we're using different up axes. bobbel and I seem to be using the positive Y axis as the up direction while you and Dragon Knight seem to be using the negative Z axis as the up direction. We've done the same thing, but just rotated 90 degrees.

Edit: Granted, I haven't looked at the actual project to see which axis it uses. I just assumed it was top-down.

Login to post a reply

Server time is: 2024-09-28 06:19:37
Your offset time is: 2024-09-28 06:19:37