Topic: Bullet script

Hey, Im making a script for a bullet.

bullet = getObject("bullet")
bullet1 = getObject("bullet1")

firing = 0

--On scene update()

if onKeyDown("MOUSE_BUTTON1") then
        if ammo_val == 1 then
        changeAnimation(char, 4)
        playSound(fire)
        ammo_val = decrement(ammo_val)
        firing = 1
        elseif ammo_val == 0 then
        playSound(click)
        changeAnimation(char, 3)
        end
    end

    if firing == 1 then
        activate(bullet1)
        bulletPos = getPosition(bullet)
        setPosition(bullet1, {bulletPos[1], bulletPos[2], bulletPos[3]})
        translate(bullet1, {0.5, 0, 0}, "local")
    end

My main question is, why wont my bullet show at the coordinates for "bullet" (which is the spawnpoint for bullet1)?

And why is the coordinates for bullet the same all the time? I've tried printed them out in the console.

Re: Bullet script

By the way, bullet is parent to player.

Re: Bullet script

if the bullet is linked to the player, the coordinates are local to player,
you should probably not link the bullets to the player because if the player rotate when the bullet is fired the bullet will rotate with it.

Re: Bullet script

I know that. smile But how should I go about it? If I cant link a spawnpoint to the player and still need the bullet to go from the playerposition?

Re: Bullet script

For exemple, when the player fire, you can initialize the bullet position and rotation according to the player :

    if onKeyDown("MOUSE_BUTTON1") then 
        pos = getPosition(player)
        rot = getRotation(player)

        -- init bullet transform
        setPosition(bullet, pos)
        setRotation(bullet, rot)

        -- if necessary move the bullet up or down, or rotate if not in the good direction :
        translate(bullet, {0, 0, 1}) -- random example you may not need it
        rotate(bullet, {1, 0, 0}, 90) -- random example you may not need it
    end

    if firing == 1 then 
        translate(bullet, {0.5, 0, 0}, "local")
    end

Re: Bullet script

Happy new year! If I use numcollision on the bullet. How can I make it more sensitive to collisions so it doesn't read out 0 when it hits something?

When I use this script I cant set X or Y values to the translate "move if necessary" because then when I rotate my player, the bullet doesn't rotate with him. smile

Last edited by Pär (2013-01-01 21:59:50)

Re: Bullet script

Pär wrote:

Happy new year! If I use numcollision on the bullet. How can I make it more sensitive to collisions so it doesn't read out 0 when it hits something?

When I use this script I cant set X or Y values to the translate "move if necessary" because then when I rotate my player, the bullet doesn't rotate with him. smile

I would try attaching(parent) an (empty object) to the end of your gun? And have your bullet's position and rotation relavent to the empty and also have the bullet spawn from that location.

You might also want to try uploading your game somewheres for others to download and test out the troubles you are having.

Last edited by zester (2013-01-02 01:56:03)

Re: Bullet script

You're saying you wanna try out my game?

Re: Bullet script

I have tried that smile But then the bullet doesn't even spawn. smile Seems as if it has to do with the local coordinates which the empty object gets from its parent-object.

Re: Bullet script

Ok, here's my immense game. Anyone who can figure out why the bullet wont have a greater collision-number than 0?

http://www.mediafire.com/?dmkk105364afza4

Re: Bullet script

I am looking at your game I found a few problems. But for now we will just focus on your question.

What I did notice was that when you "fire" your pistol the bullet only sometimes fires and
it never re-spawns.

This code isnt right., for one isCollisionBetween by default assumes there is going to be a collision event, and by using "not" your reverting its expected result.       

if not isCollisionBetween(player, bullet1) then
    if bcoll > 0 then
        deactivate(bullet1)
        playSound(reload)
    end   
end


You would write it like this:

if isCollisionBetween(player, bullet1) then
    print("You shot the sherif")
else
    print("Crap you missed and he is mad!! RUN!!!")
end



You can give your bullet a "follow" behavor the settings I used was
delay 0.00
x: 0.12
y: 0.55
z: 0.44
local: Enabled

With those settings the bullet moved and rotated properly with the character. I was able to walk up to the bridge and shoot one of the houses.


Lastly I would create a new scene to test in "A simple shooting range" with
1. A "plane" for ground
2. Your character
3. The bullet
4. A Target "Cube"
Once your shooting action is working right then bring that code into your main scene.


I have a question for you did you do the "walk cycle animation" your self or was that something you found somewheres?

Re: Bullet script

I did it myself. smile

Thanks for the info! I didn't think about the follow behavior.

Re: Bullet script

Hm, the num_collision still reads 0 in the console. Can you turn the collisionsensitivity up somehow?

Re: Bullet script

Pär wrote:

I did it myself. smile

Thanks for the info! I didn't think about the follow behavior.

Let us know what kind of game your making, story line maybe. What ideas you have.

And if you would like I wouldnt mind contributing some models/textures. If you dont mind that
what ever I create also goes on the wiki for others to use.

Re: Bullet script

Pär wrote:

Hm, the num_collision still reads 0 in the console. Can you turn the collisionsensitivity up somehow?

One sec let me look at the problem with a simple example.

Re: Bullet script

Im making an RPG game, there's no storyline but the game will have immense freedom and I'm looking to make a dynamic world which reacts. A storyline can be added if wanted.

And I'm focusing on making it multiplayer sometime later.

Sure, I would love if you made a sack which I could use. I need a pile of sacks laying on top of each other.

Re: Bullet script

I did a collision test at differant velocities between three differant objects and everything worked fine. So I am not sure whats going wrong with your code.

Sure, I would love if you made a sack which I could use. I need a pile of sacks laying on top of each other.

Like these? If yes both full and empty?
http://www.fallingpixel.com/products/38986/mains/000-3d-model-Previw0.jpg

Last edited by zester (2013-01-02 21:29:22)

Re: Bullet script

Yes, exactly. smile

Well I will have to run some tests myself.

Re: Bullet script

Pär wrote:

Yes, exactly. smile

Well I will have to run some tests myself.

Ok cool I can use bags like that also in my project.
http://forum.maratis3d.com/viewtopic.php?pid=3173#p3173

Re: Bullet script

Nice!

Re: Bullet script

Here is a first attempt, Ill make differant sacks fter I finish with this ones texture.

Sack Full #1
http://i49.tinypic.com/13zzwvr.png

Download Link

Last edited by zester (2013-01-02 22:54:48)

Re: Bullet script

Wow! It looks really good! Can you upload it to another mediasite? Google has a hard time.

Last edited by Pär (2013-01-02 23:16:55)

Re: Bullet script

Does this link work for you?
http://zester.googlecode.com/files/Sack.zip

Re: Bullet script

Yes! Thanks.

Re: Bullet script

You can check the asset section of the wiki for models, thats where I will be adding them. http://wiki.maratis3d.org/index.php?title=Assets

There is a mushroom in the Organic section if you need one.