Scripted player's weapon shoots wrong.

Topics regarding Scripting with Reality Factory
Post Reply
Danimita92
Posts: 335
Joined: Sat Feb 09, 2008 5:47 pm
Location: Lanzarote/Canary Islands/Spain

Scripted player's weapon shoots wrong.

Post by Danimita92 »

Hi everybody, let me first say that this is one of my first tries to make my scripted player shoot. Okay, so in the scripted player's script I've got this for when he shoots:

Code: Select all

if(IsKeyDown(72))
            {
                SetTargetPoint(0, 0, 216);
                FireProjectile("disk","Hand_R",0,0,0,"Health");  // shoot the projectile
                AnimationSpeed(3);
                Animate("Shoot");
            }
And it does shoot, but what happens is that
1- It shoot's a little to the left of where I'd like it to shoot.
2- When I aim up and shoot, the projectiles go towards the floor, and when I aim to the floor, the projectiles go towards the ceiling.

How could I fix these problems? Thanks in advance.
Danimita92
Posts: 335
Joined: Sat Feb 09, 2008 5:47 pm
Location: Lanzarote/Canary Islands/Spain

Re: Scripted player's weapon shoots wrong.

Post by Danimita92 »

Nobody? Is it hard to understand my problem, or is it just you don't know the answer
Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Re: Scripted player's weapon shoots wrong.

Post by Jay »

You set a specific point in space as your target point. That means the projectile always wants to fly there. Try to use FireProjectileBlind instead or modify the target point to where you want it.
Everyone can see the difficult, but only the wise can see the simple.
-----
Danimita92
Posts: 335
Joined: Sat Feb 09, 2008 5:47 pm
Location: Lanzarote/Canary Islands/Spain

Re: Scripted player's weapon shoots wrong.

Post by Danimita92 »

Arg... it won't work! I change FireProjectile for FireProjectileBlind and included the other two settings you can put in this version (I'm using 0.75C) and when I hit the shoot button it'll crash with the typical "Send Report" button and all that. This is what I have:

Code: Select all

if(IsKeyDown(72))
            {
                FireProjectileBlind("disk","Hand_R",12,0,100,"Health","Camera",100);
                AnimationSpeed(3);
                Animate("Shoot");
Danimita92
Posts: 335
Joined: Sat Feb 09, 2008 5:47 pm
Location: Lanzarote/Canary Islands/Spain

Re: Scripted player's weapon shoots wrong.

Post by Danimita92 »

It won't work, I reinstalled RF and now it won't crash when I use FireProjectileBlind, but it still goes up when I aim down, and viceversa:

Code: Select all

if(IsKeyDown(72))
            {
                FireProjectileBlind("disk","Hand_R",12,0,100,"Health",self.camera_pitch,100);
                AnimationSpeed(3);
                Animate("Shoot");
            }
User avatar
bernie
RF Moderator
Posts: 1249
Joined: Tue Nov 15, 2005 10:07 am
Location: Ireland

Re: Scripted player's weapon shoots wrong.

Post by bernie »

Just a thought... make the camera pitch a negative value ie.
FireProjectileBlind("disk","Hand_R",12,0,100,"Health",-self.camera_pitch,100);
and see what happens.
Danimita92
Posts: 335
Joined: Sat Feb 09, 2008 5:47 pm
Location: Lanzarote/Canary Islands/Spain

Re: Scripted player's weapon shoots wrong.

Post by Danimita92 »

:cry: Nothing, it won't work. I even tried multiplying self.camera_pitch by (-1) but it won't do anything. Anyway I uploaded a youtube video that shows what's happening.
http://www.youtube.com/watch?v=XaqIh9xN6dk
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Scripted player's weapon shoots wrong.

Post by Juutis »

Would you mind posting the whole script? Or at least all the parts that have something to do with shooting (Rotating the player etc.). I had a similar problem but playing around with different rotations fixed it.
Pain is only psychological.
Danimita92
Posts: 335
Joined: Sat Feb 09, 2008 5:47 pm
Location: Lanzarote/Canary Islands/Spain

Re: Scripted player's weapon shoots wrong.

Post by Danimita92 »

Sure, here it is:

Code: Select all

{
Spawn[()
   {
       BlendToAnimation("Aimdown", 1, false, "");
       self.pitch_speed = 280;
       Console(false); //Turns on debug
       HideFromRadar(true);
       BoxWidth(20);
       BoxHeight(40);
       LowLevel("Setup");
    }]

   Setup[()
   {
        yaw_speed = 180;
        self.ideal_pitch = -self.camera_pitch;
        self.ideal_yaw = self.player_yaw;
        SetTargetPoint(0, 0, 0);
    if(IsKeyDown(73))
        {
            PawnRender(true);
            AnimationSpeed(1);
            yaw_speed = 1280;
            self.ideal_pitch = -self.camera_pitch;
            self.ideal_yaw = self.player_yaw;
            ChangeYaw();
            ChangePitch();
            camerapitchtemp = self.camera_pitch*10;
            PositionToPawn("rotation",0,75+0+camerapitchtemp,0+camerapitchtemp,true,false);
            if(self.animate_at_end = true)
            {
                Animate("Aimdown");
            }
            if(IsKeyDown(72))
            {
                FireProjectileBlind("disk","Hand_R",12,0,100,"Health","Camera",100);
                AnimationSpeed(3);
                Animate("Shoot");
            }
        }
    else
       {
           PawnRender(false); 
           SetEventState("AIM", false);
       }
   }]       
}
When you right click, the pawn appears, and rotates like a normal first person weapon. Then when you left-click it shoots.
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Scripted player's weapon shoots wrong.

Post by Juutis »

Oh, you've faked it really well! :shock: It really looks like the guy is only turning his upper body up/down but actually the whole model is turning. Well, yeah, you can't see his legs unless you aim very low. Anyway, well done. :)


When my scripted weapons were shooting up when aiming down and vice versa I did a few things:
Initial (when things went wrong):
Pawn.ini -> actorrotation = 0 180 0
script -> self.ideal_pitch = self.camera_pitch; and self.ideal_yaw = self.player_yaw;
3D model -> just like you'd expect it to be, facing forward

Fixed:
Pawn.ini -> actorrotation = 0 0 0
script -> self.ideal_pitch = self.camera_pitch; and self.ideal_yaw = self.player_yaw; (no changes)
3D model -> Now here's the trick; Rotate the model 180 degrees in the modeling application to make up for the change in pawn.ini. So now your model is facing the back but the actorrotation in Pawn.ini makes it correct again. Now, if you start thinking about it, how the changes affect the way the pawn rotates and stuff, it makes sense. I'm not gonna even try to explain why but it really does. :D And for me it fixed the problem. 8)
Pain is only psychological.
Danimita92
Posts: 335
Joined: Sat Feb 09, 2008 5:47 pm
Location: Lanzarote/Canary Islands/Spain

Re: Scripted player's weapon shoots wrong.

Post by Danimita92 »

Loads of thanks, Juutis, it worked perfectly :wink: I owe you one
Post Reply