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.

AppGameKit Classic Chat / firing projectile from gun(3d)

Author
Message
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 25th Mar 2017 21:55
Hi,now I have a gun I looked into shooting bullets of to test spheres from it, here is the code I have so far:



As you see I have taken code directly from the 3d physics examples on this forum, yet on running and pressing the v key, the sphere simply shoot downward rather than in the direction of the camera! Anyone know why, if you need a video of what happens then I will post one!


Hail to the king, baby!
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 25th Mar 2017 23:42
A mass of 300 is quite heavy. What do you have the gravity set at?
SetObject3DPhysicslinearVelocity() takes a direction vector you are just giving it a angle.
The coffee is lovely dark and deep,and I have code to write before I sleep.
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 26th Mar 2017 16:20
hmm,your're right, I changed the mass, I think I changed it at one point to test, but still no joy, pretty sure I am just doing what the code in the example does but will look again!
Hail to the king, baby!
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 26th Mar 2017 19:14
ok still cannot do this, how do I indeed fire a object from the 3d rectangle in the direction it is facing!
Any help would be appreciated
thanks
Hail to the king, baby!
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 26th Mar 2017 21:02 Edited at: 26th Mar 2017 21:05
Like I said above that SetObject3DPhysicslinearVelocity() takes a direction vector you are just giving it a angle.
Instead try this. You may need to change variable names to suit your code.

The coffee is lovely dark and deep,and I have code to write before I sleep.
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 26th Mar 2017 21:44
could you tell me what value gets passed to gunPositionVec please? I know nothing of these vectors
Hail to the king, baby!
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 26th Mar 2017 22:13 Edited at: 26th Mar 2017 22:15
Create a vector which holds the XYZ position of the gun.



If you are going to program in 3D you really need to learn about vectors. They make vector math simple like using a calculator
when you need to add or subtract.

P.S. Remember you need to delete vectors when you are finished with them.
Here is a learning experience for you, figure out where you need to delete the vector in the function I posted above.
The coffee is lovely dark and deep,and I have code to write before I sleep.
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 26th Mar 2017 22:21
ok I assumed the gunPositionVec was just creating a vector3 of the guns x/y/z position, so upon pressing v to fire I put:




and had changed the throwball function to:


the function that sets all this off,or rather the main level test function looks like this:



As you see the gun gets created just before the main repeat-until with gun = createobjectbox(0.25,0.25,10)
This is the Result however:



not quite right!




Hail to the king, baby!
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 26th Mar 2017 22:22 Edited at: 27th Mar 2017 00:40
ah,lol...least I got that right about the vector,had been creating this post whilst you replied!!
ok I have yet to delete the vector,if that is my problem,hmm..i would say you delete it after using it? so maybe before the line
//3D Physics code

I definitely had a think about and looked up vector3,learned it,and now I know! But as you see in the video it still aint working correctly
As it stands it always wants to fire directly behind me!,so always the opposite direction,unless I turn the camera 180 on the y and then it looks in the direction it wants to fire!
Hail to the king, baby!
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 27th Mar 2017 00:48
First you would not want to delete the projectileDirVec Vector until the end of the Throwball() function
since you need to use it to set the velocity. I can not debug your code based on a few code snippets.
Your code is very spaghetti like and this makes it hard to debug. You need to write your code more modularized
like in the physics demos I posted. You should have a proper DO/LOOP with function calls.
I can only guess by the video on what is causing the problem. Remember the best code is the code that
is easy to debug.

First guess you have the gravity set incorrectly and or the scale factor for the physics world is incorrect.
Since I can not see those lines of code I have no way of knowing.

Second guess is that the direction vector for the ball is reversed. Since I do not know which way your camera is pointing
try reversing the vector, change this line in the throw ball function. Move the box negative on the Z.



Third guess is, in the video the ball seems to be traveling to fast try decreasing the speed to see what is happening.


The coffee is lovely dark and deep,and I have code to write before I sleep.
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 27th Mar 2017 09:06 Edited at: 27th Mar 2017 11:45
ah,thought you meant the gunPositionVec.. but yeh thats where I ended up putting them both to delete them. at the very end of that function, anyhw the scaling is correct and so is the gravity because the rest work fine including the character controller, it is pointless shwoing any more code as the rest is the editor that this is all built with/into.


As far as it being spaghetti code..well I hope not,it is pretty clean!

here is the whole code anyhow: just note the editor and everything is all there.

But as you see the sizes seem fine

the sizes are set to 60 by default(sx#,sy#sz#, radius#) for creating the primitives
the images are done in a pretty Simple manner though, I have them named numerically so 1.png,2.png and so forth then loded in with a simple for next! I know that could be better,so as long as you have a few name 1.png,2.png..perhaps just half a dozen then that code runs just fine! If you are interested in helping me then I can explain to you directly the whole workings of this and how it functions but just helping with this bullet thing would be/is awesome! btw I tried moving the z with a minus but no joy,though it at least starts off shooting correctly,it is when I turn the camera around.

I will clean some code up today that I admit I havent been doing!

The whole thing is still pretty much a work in progress and things like the placement of lights, in which I simply press l to switch between placing lights or primitives, could most def be implemented better, I need to change the cursor to a lightbulb in light editing mode then back to a primitive in normal mode, but that is just something I have yet to get around to doing!

Anyhow I set the gravity to 0 on all axis to have a better look at what is going on, here is what it does:

Hail to the king, baby!
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 27th Mar 2017 12:48 Edited at: 27th Mar 2017 13:58
cleaned code up some, Here

Added/fixed the lights thing so pressing L switches between correctly and only shows relevant edit boxes and objects.

Hopefully you can see the scale of the project!

But cleaned up some now to tie it more in the gametype and editmode, the only gametype to set atm is 0 as that is all I have done, this stuff needs expanding and I am guessing I need to create a player type to make it less of a mess which I will eventually do!
A quick rundown of how to use this:

So basically what you do is lay down a few blocks for the ground, then change the value in group to 1 along with changing the value next to phybody to 2, this is all based on group values and 1 is always used for the player! place an object with that group value of 1 above ground level as we always need a player at least! and press T to test or F4 to save... you dont have to save to test but saving is usually a good idea... F1 is to load, c is to clear, s is to change shape, bracket keys change textures, use cursor keys to move around and A-Z to raise lower, pressing any of these with Ctrl pressed in moves based on the smooth# value for finer placement. Pressing k will clear all lights from the level. Oh and space bar actually places something!!

Pressing shift on placed object should select to delete by pressing the delete key,it does support multi-select but only seems to work well with the plane shape used, cannot quite get the raycasting correct! another thing that needs sorting but pretty low on the list.
Hail to the king, baby!
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 27th Mar 2017 13:55
Ok, I think I figured out what is happening. I may have made a mistake when getting the gun position vector.
Try this get the world XYZ position of the gun instead.



The coffee is lovely dark and deep,and I have code to write before I sleep.
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 27th Mar 2017 13:59 Edited at: 27th Mar 2017 13:59
ok will try, I wouldnt mind more positive feedback at what I am trying to achieve! I am going to release the whole code anyhow once it is all sorted!
Hail to the king, baby!
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 27th Mar 2017 14:25 Edited at: 27th Mar 2017 14:43
Also change this line in the ThrowBall Function.



The coffee is lovely dark and deep,and I have code to write before I sleep.
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 27th Mar 2017 16:00 Edited at: 27th Mar 2017 17:31
tried the change,still the same thing?!
Pastebin
While I am at stuff I have uploaded the project to my google drive for safe keeps, so the whole thing is HERE.
Included are the media files I use of course.
Hail to the king, baby!
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 28th Mar 2017 04:29 Edited at: 28th Mar 2017 04:37
OK I think I got it figured out. I downloaded your whole project.
I had to make a small demo to see what was happening. I did not have time to
check the rest of your project for bugs but if you just change this function it should work.
From looking at your project you were actually on the right track when you thought it was a rotation problem.
It just needed the world rotation of the gun so when you move the projectileDirBox on the local z it is always
creating a forward direction vector.



P.S. You can use this method of creating a direction vector for ray casting also.
The coffee is lovely dark and deep,and I have code to write before I sleep.
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 28th Mar 2017 09:06 Edited at: 28th Mar 2017 12:44
Ah! fantastic! Yeh this works fine, I would never have sussed it out so thanks!


The project does have a few issues,if ever you are bored then perhaps you can look at them, one is the uv texturing, It has a trepeat box which if set to 1 should repeat but I never got it right with the scaling, this code is scattered around so first I need to make a function for it to hold it in one place!

the other thing is indeed that raycasting for selecting objects, it is so bad at the moment I cannot even use the plane as an actual shape to use and instead it is used to actually select other objects! Very bad but I need to be able to delete and multi select to change textures which you can do by selecting objects, then changing the value in the texture box! But usually only with the flipping plane as the selection tool. If you press s of course you eventually get to the plane shape, forgot to mention earlier that pressing i+o in the editor rotates the camera on the for a more head on view, handy in certain circumstances! One other thing I half implemented I guess is any object placed with a group value of 7 will play a video on it but a file called mov1.avi needs to be in the media folder, hoping it to be a feature I can use! But anywayz thanks again!

**Edit **
one small thing I found is that in Function clear_level() a few lines needed adding,simply forgot!

I had added the fields later on in the project to account for the different light modes one can choose. Dont know if you added lights but I doubt you changed the light mode anyhow! it defaults at 0 of course but can be changed to 1(blinking) or 2 for flickering or 3 for pulsating, I will probably tie in the radius# edit box to the radius# of the light but just have it a fixed value atm, another thing on the to do list!
My next course of action is to now create a proper type for the player and have fields like ammo and health and stuff like that, a place to store these (bullet) ID's so I can control what gets created/deleted, it will clean up a lot of code and not have stray bullets strolling around the editor after quitting the level test!
** edit **
Realised I hadnt given any way to change the level number to edit with, so coded in another box to change it, totally skipped my memory!
Updated the file on my google drive that is linked above with the changes.
Hail to the king, baby!
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 28th Mar 2017 13:35
Try running it in debug mode and you will see the current errors.
One of the errors may solve your UV problem.
The coffee is lovely dark and deep,and I have code to write before I sleep.
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 28th Mar 2017 14:14 Edited at: 28th Mar 2017 14:32
with trepeat set to 1 or 0? or either?!
I know it aint right what I am doing anyhow along with the scaling of the objects so have to rethink it all and for that matter have it in a function!

**edit**
Taken care of that function and updated the project file,much cleaner! So we are now just dealing with the Function check_repeat(ob,trep)
Hail to the king, baby!
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 28th Mar 2017 18:08
Try adding this as the first line in your code file it will show you the errors.

SetErrorMode( 2 )
The coffee is lovely dark and deep,and I have code to write before I sleep.
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 28th Mar 2017 18:56 Edited at: 28th Mar 2017 22:12
image not to the power of 2 huh,ok sorted that, and deleted that sprite error, weird,wonder what i was doing with that!
But still anyhow the function check-repeat aint right and I dont believe for a sec I am dong it right! Anyhow updated files with the change and of no errors in debug mode!
Well,not now anyhow!!

Ok so can yoiu help me with the uvtexturing? I am thinking if the scale is <1 then I divide and if> then multiply?? not sure, and which scale vars do I used?!
Hail to the king, baby!
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 31st Mar 2017 22:21
I figured I would post this here since this was all about direction vectors.
Here is a reusable function to get a direction vector for an object. It could help to clean up your code.
Always make a function for anything reusable.
I added the normalization of the vector so it can be used easier for other calculations.
The 3D physics commands automatically normalize the vectors that you pass in so it will not matter
for those commands whether it is normalized or not.

The coffee is lovely dark and deep,and I have code to write before I sleep.
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 1st Apr 2017 16:25 Edited at: 1st Apr 2017 16:26
ah thanks,much appreciated, changed the editor quite a bit:
here is the progress:



I realised I was asking for the impossible with the uv texturing to what I needed,so decided to have a wall to place or a ground piece, both being their own group, and depending which has been chosen dictates the way it is uv textured! I can now resize each piece if I wanted to and still have an exact texture match.
Hail to the king, baby!
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 25th Apr 2017 20:26 Edited at: 25th Apr 2017 20:28
Stab in the Dark software

Sorry to dig this up again, but how do I use them functions .
I have come to the point of basic A.I but found problems with the direction thing again, this function I wrote:

But of course find it is stuck in the default direction!

So basically I want to point the direction of baddie[n].id to the player object somewhere in that function using the 2 functions of yours.
Hail to the king, baby!
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 25th Apr 2017 21:16 Edited at: 25th Apr 2017 21:20
To get a direction vector you just subtract point A from point B and normalize the result.
The function I posted above ( GetObjectDirectionVector )does this by creating a temp object and moving it away in the direction desired.
This provides a point B to subtract from point A then just normalize the result.

Here is a function using vectors that will give you a direction vector.



P.S. I just noticed I had a typo in the GetObjectDirectionVector() function I posted above.

The coffee is lovely dark and deep,and I have code to write before I sleep.
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 25th Apr 2017 22:47


Also an endselect was missing! I think it goes there?


Anyhow, I must be dumb coz i still dont know how to use them! could you give me an example in my function calling it please? the baddie_control(), within the for next loop if you take baddy[n].id as the objectID that needs to move toward player... thanks if you can!
Hail to the king, baby!
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 26th Apr 2017 03:29
You need to write the example, otherwise you will not learn. It is how I learned.
Just write out in comments step by step what you want to accomplish logically.
Then after each comment try to write the line of code needed to accomplish that step.
It will not be perfect the first time thru but after a few alterations you will find you have it figured out.
Your not dumb but your are persistent and that is what makes a good programmer.

Then post your code where you are trying to use the functions and I can give my opinion on which way it should be.
Oh yes I missed the endselect, good catch. I have gotten to use to programming in C++.
The coffee is lovely dark and deep,and I have code to write before I sleep.

Login to post a reply

Server time is: 2024-11-24 17:08:13
Your offset time is: 2024-11-24 17:08:13