Need some help with things

Blitz3D Forums/Blitz3D Programming/Need some help with things

Rrtaya_Tsamsiyu(Posted 2014) [#1]
So, i've been learning blitz 3d, been going good so far. Ran across a few problems i haven't been able to solve.
i made simple game, where you can use either a tank or an airplane to shoot at targets. At first i made the controllable vehicles as individual objects, not in a type. The targets and projectiles were types though. Worked fine.

Now i'm trying to make the vehicles types too.
Main issue i'm dealing with right now is i'm not sure how to get the projectiles to shoot from the right place again.

Also having some basic issues with collisions, and child objects not rotating when used in a type, i'll probably ask about that later.

i'll elaborate below. i can also put the whole game code up as a download if that's better.
Any help is appreciated:]

So, in the main loop, it calls a function that checks all the targets, which now includes the controlled vehicles, because they're types now.
When its iterating through all the targets, it checks a flag on each target to see if it's controlled.

If it's controlled, it goes through all the hitkey checks, and fire the gun if that key was hit. i had copy everything in my hitkey function to the target check, because i don't know how to use thisWhatever outside of the for/next loop that's checking everything. [..or is the current 'this' a Global thing?]

i hope im not speaking too much gibberish..

Anyways, i've been trying to keep my fire gun function separate. i tried a couple of things, one of the most recent is this.

FireGunXYZ_PYR[0] = EntityX#(thisTarget2\Barrel1)
FireGunXYZ_PYR[1] = EntityY#(thisTarget2\Barrel1)
FireGunXYZ_PYR[2] = EntityZ#(thisTarget2\Barrel1)
FireGunXYZ_PYR[3] = EntityPitch#(thisTarget2\Barrel1)
FireGunXYZ_PYR[4] = EntityYaw#(thisTarget2\Barrel1)
FireGunXYZ_PYR[5] = EntityRoll#(thisTarget2\Barrel1)

Basically, the array sees what the barrel's position is. Then, i call the fire gun function that makes a new type for the bullet, and it uses the array's data to see where to spawn it.

But, instead of spawning at my vehicle, it spawns at the original type at 0,0,0 that the vehicle is based on.

i wouldn't be surprised if i'm going about shooting projectiles wrong, lol. Worked fine before converting my controlled object to a type though.

Again, i can post all of my code, and i can post my code that i had before trying to convert to a type if that's needed, to show how it should look once everything's done.

Thanks in advance for any help


RemiD(Posted 2014) [#2]
Some concepts :

->you can use Dim arrays or Type or a combination of the two to store variables and references of pivots/meshes/textures/images

->if the list has not many entities, you don't need to store the id/handle of each instance because on modern computers it will be fast to search/find an instance in the list and access its variables and references.

->it is however useful to store the id/handle of Player so that you can access its variables and references without having to use a for next loop

You can see a code example on how to create/manage lists with Dim arrays or Type here :
http://www.blitzbasic.com/codearcs/codearcs.php?code=3094 (with Dim arrays)
http://www.blitzbasic.com/codearcs/codearcs.php?code=3095 (with Type)

to access a specific instance in a list with Dim arrays you can use the id% of the instance :
ThingRoot(id)
ThingMesh(id)
ThingLife(id)

to access a specific instance in a list with Type you can use the handle% of the instance :
t.Thing = Object.Thing(handle)
t\Root
t\Mesh
t\Life


Rrtaya_Tsamsiyu(Posted 2014) [#3]
Thanks for the help. From what you said it seems i'm needing to access the instance of a type.

i looked at the links right quick. Some of the info in there might solve some other things i'm wanting to figure out too.

is this referring to the link you gave me about types?
to access a specific instance in a list with Type you can use the handle% of the instance :
t.Thing = Object.Thing(handle)
t\Root
t\Mesh
t\Life

if so i'll go study the linked post more, if not please elaborate.

Reading what you posted, i think i can state my issue more accurately; i have an instance of a type in a for loop in function A, and i'm trying to tell function B which instance that is. i think that's how i should put it anyways.


RemiD(Posted 2014) [#4]
each time an instance of a Type list is created, you can use Handle(i) to get the instance id.

example :

Notice how the handle increases each time an instance is created whatever the Type list.

In the code examples i recommend you to read, you can see how to store the kind (=listname) and the handle of an instance in the "entityname" and then retrieve the kind and the handle after a collision or a linepick and then use the kind and the handle to access the specific instance of a specific Type list.


Rrtaya_Tsamsiyu(Posted 2014) [#5]
Ok, i'm pretty sure i'm getting this.
i'll go back through the info you gave me and experiment, thanks again


Rrtaya_Tsamsiyu(Posted 2014) [#6]
Currently trying to clone bits of code from the example to understand it better, haven't been able to get it to work. Right now i'm trying to make it where when a bullet hits something, it will show what the kind and name of the object it hit, mimicking the function of the example program. Not sure where to go from here, other than continuously trying random things.

One thing i did was copy paste the collider into my shell code, it didn't give me the name and kind. Then i got rid of ColliderE pivot and replaced the references with a reference of my bullet, like in this line
CollidedCollidable = CollisionEntity(ColliderE,1)
Still didn't give me the name and kind.


One thing that i've had come up a few times is an error on this line;
CollidedId% = Right(CollidedName,Len(CollidedName)-3)

It keeps saying the value on the end needs to be positive. What would cause this to be a problem all of the sudden?


RemiD(Posted 2014) [#7]
You need to give a name to a collidable/pickable mesh/shape before you can retrieve it...

NameEntity() allows you to give a name to a mesh/shape
EntityName() allows you to retrieve the name of a mesh/shape

See how these functions are used in the code examples.


Rrtaya_Tsamsiyu(Posted 2014) [#8]
Ok, thanks.
Edit;Works great! :]

Huh, i started out asking mainly about how to get stuff to shoot from the right place
and ended up with my collision issue being solved lol. i'm guessing it still has to do with
naming and retrieving names though. i'll continue experimenting with it


Rrtaya_Tsamsiyu(Posted 2014) [#9]
i sorta jury rigged the plane to where the shells come from the right place on it using move entity, this
won't work for the tank though. i think my next problem is along the same lines, so i'll ask about it.

Right now my issue is that the turret and barrel won't turn. Both of these are child objects.
Currently i'm using a for loop, and my keydown checks are in that loop. This is a line of code that should turn the turret;
If KeyDown(RIGHTKEY) = True Then TurnEntity thisTarget\Turret,0,-5,0

The barrel and turret on the object i am controlling won't turn, but the original ones at 0,0,0 turn.
They were working before i went from using the original objects to using a type that stores all the objects.
What might be causing this?


RemiD(Posted 2014) [#10]
A possible cause may be because the instance you are trying to turn is not the correct one.

To check you can use the handle of the instance :
Handle(thisTarget) must correspond to the handle of the instance you are trying to turn.


Another possible cause may be because of a parent/child problem, the child may not have been set properly.


Rrtaya_Tsamsiyu(Posted 2014) [#11]
hmm. Right now my original objects have the hierarchy set to them, and the types just copy the originals. Visually it's worked ok so far, it might be causing the other issues though. i'll check the handles too


Rrtaya_Tsamsiyu(Posted 2014) [#12]
Tested stuff on the plane, the handles are correct. Also tried loading my child meshes whenever i make the type, instead of making a copy of an already loaded mesh, this didn't work either.

i'm wondering if it's possible to put both meshes into one type, i might just have to make a type for each object and then put them together by updating the position of each turret and barrel using position entity instead of using parent/child.