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 / aiming with crosshairs

Author
Message
farmkid4
15
Years of Service
User Offline
Joined: 23rd Sep 2009
Location: on my pc :)
Posted: 1st Dec 2009 01:31
Hi guys after about 1/2 an hour of searching the forums and reading posts i have some questions.

I am making a game in which you are going to be trying to destroy snowmen with snowballs. I need to know how to make the snowball fly in an arc depending on where you aim the crosshairs.


example:
---------------------|
key += crosshairs |
.... path of snowball|
---------------------|



+ ....
..

i hope you get the idea if you need more to go on just ask.

thanks for the help.

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 1st Dec 2009 18:42 Edited at: 1st Dec 2009 18:47
Cross-hairs aren't really suitable for throwing snowballs as they are very low velocity and dont travel in a straight line for very long.

Cross-hairs are really for high speed projectiles like bullets which travel in a straight line for long distances.

You might be better off with a power meter which goes up and down and the user hits the space bar at the required strength level. The power for the next throw could then be judged depending on where the last snowball landed.

Using this method, you would point a snowball in the required direction based on the X and Y angle of the thrower and use Move object with the power level selected. Applying a gravity value onto the object as it moves would make it drop to the ground in an arc.

TDK

farmkid4
15
Years of Service
User Offline
Joined: 23rd Sep 2009
Location: on my pc :)
Posted: 1st Dec 2009 19:41
hmm i hadnt thought of that. How would i go about applying gravity to an object?
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 2nd Dec 2009 02:20 Edited at: 2nd Dec 2009 02:52
If you want basic 'simulation' rather than 'real-world' physics then it's no more than having 'gravity' and 'velocity' float variables.

If you place an object at Y=3.0 off the ground, point it in a given direction then it will continue in a straight line when you move it as only the X and Z values will change (the Y height remains constant).

So, each time you move the object, you decrease the Y height value by the gravity variable making the object move down as well as forward.

But this being a constant value results in a straight line downwards (like a flat ramp).

So, what you do is increase the gravity value very slightly each time the object is moved - by adding an 'acceleration' value. (You can always add a check to stop the gravity value increasing above a certain amount to resemble 'constant velocity' if you need to).

So, you would start off with something like:

Gravity# = 0.005
Acceleration# = 0.001


and in your move object loop:

Move Object ObjNum,ReqDist#
Inc Gravity#, Acceleration#
NewYVal# = Object Y Position - Gravity#
Position Object X#, NewYVal#, Z#
Sync


Note: Not real code - only to demonstrate the principle.

The values you use depend entirely on the scale you are using for your program. For example, if your snowballs are spheres of size 5 you would need to use bigger values for both gravity and acceleration.

Simply reset the Gravity# value when the next snowball is fired.

Example:



This is DBC code but should work OK in DBP.

TDK

farmkid4
15
Years of Service
User Offline
Joined: 23rd Sep 2009
Location: on my pc :)
Posted: 2nd Dec 2009 14:32 Edited at: 2nd Dec 2009 19:29
thanks for the code. I have it so you can walk around the map but when i add that doe it doesnt work if you can help i d appreciate it i will edit this post if i figure it out before you guys answer.

thanks again
edit:
ok what i mean is the snowball throws from the corner instead of where i am standing.
farmkid4
15
Years of Service
User Offline
Joined: 23rd Sep 2009
Location: on my pc :)
Posted: 9th Dec 2009 01:19
ok i got that working but i want to be able to have it so that the snowball throws straight wherever you are looking any tips/help with how to accomplish this?




sorry about the double post.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 9th Dec 2009 22:36 Edited at: 10th Dec 2009 00:05
Locate the line:

Position Object 1,0,3.0,0.0

This is where the snowball starts. As you move around, you position the snowball at the player character's current X,Y,Z position (or the camera's position if you are doing it FPS-style).


Rotate Object 1,330.0,0.0,0.0

This line points the snowball in the required direction ready to fire. So, like when positioning, rotate the snowball up/down with the player/camera.

As I mentioned before, one method of throwing is to have left/right aiming, alog with a power bar. The higher the bar when you press space, the harder (further) you throw in the direction you are facing. (No up/down aiming).

Another method is to have left/right aiming, an up/down display to set the vertical angle and a power meter - a bit like Worms if I remember correctly.

Finally, you also have the option to fix a cross hair in the centre of the screen. When you aim, the up/down angle of the camera would give you the angle to set the snowball.

I'll have a little play while you see what you can come up with yourself...

[Edit] I've modified my first snippet to point you in the right direction. It's not perfect, but should give you some ideas...



TDK

farmkid4
15
Years of Service
User Offline
Joined: 23rd Sep 2009
Location: on my pc :)
Posted: 10th Dec 2009 02:09
thanks you much for the help TDK i will see what i can do

Farmkid

When in doubt use the search bar.

Login to post a reply

Server time is: 2024-11-24 23:18:57
Your offset time is: 2024-11-24 23:18:57