Forum: Grand Theft Auto Series Modding - Our GTA Modding Team is the best around. Tutorials & Topics related to modding your GTA games, trophies, and save files! Discuss GTA game modding with the knowledgeable members of PSX-Scene and the Official GTA IV Mod Team.


The above video goes away if you are a member and logged in, so log in now!




 
Would you like to get all the new info from
PSX-Scene in your email each day?




Want to learn more about the team keeping you up to date with the latest scene news?

Read about them now!

Check out our Developer bios, too!

 


User Tag List

Like Tree1Likes

Thread: Object will not move when applied force to?
  

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
  1. #1 Object will not move when applied force to? 
    Emmanuel U's Avatar
    Emmanuel U is offline Developer
    Join Date
    Oct 2012
    Posts
    76
    Downloads
    0
    Uploads
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Likes Given
    89
    Likes Received
    65
    So I was messing around with Jumper/JDM's rocket gun the other day and decided to make a dildo gun. I got the dildo to spawn but for some reason it just sits in front of me instead of shooting forward like how it should. Here's the source and any help is appreciated.

    Code:
    void rocket_aim(void){
    		GET_CURRENT_CHAR_WEAPON(GetPlayerPed(), &wWeapon);
    		if((wWeapon == WEAPON_PISTOL) && (IS_BUTTON_PRESSED(0,BUTTON_L))){
    		
    			GET_GAME_CAM(&game_cam);
    			if (IS_CAM_ACTIVE(game_cam)){
    				GET_CAM_ROT(game_cam, &gcrotX, &gcrotY, &gcrotZ);// used for setting the object rotation and for some weird trig stuff below
    				GET_CAM_POS(game_cam, &gcX, &gcY, &gcZ);// used for the spawn point of the object, because the player is offset while aiming
    				if (gcrotX < 0.0)// the range for cam rot is -180 to 180, to set object rot we need 0 to 360
    				{
    					objrotX = gcrotX + 360.0;
    				}
    				else
    				{
    					objrotX = gcrotX;
    				}
    				if (gcrotZ < 0.0)
    				{
    					objrotZ = gcrotZ + 360.0;
    				}
    				else
    				{
    					objrotZ = gcrotZ;
    				}
    				/*  the trig stuff below could possibly be replaced with vectors, I have no idea how to do that though.  *
    				*   I apologize if this is confusing, but if you want to change the distance from the game_cam that the  *
    				*   object is spawned, adjust "3.0" to your preference on the first and fourth lines.  Also prjT is the  *
    				*   adjacent side from the pitch calculation, its purpose is to be the tangent in the following 2 lines */
    				prjT = (3.0 * COS(gcrotX));       // adj side calculation to be used as a tangent below
    				prjX = gcX - (prjT * SIN(gcrotZ));// calculates how far to spawn the object from the game_cam on the X plane
    				prjY = gcY + (prjT * COS(gcrotZ));// calculates how far to spawn the object from the game_cam on the Y plane
    				prjZ = gcZ + (3.0 * SIN(gcrotX)); // calculates how far to spawn the object from the game_cam on the Z plane
    			}
    		}
    }
    
    void rocket_shoot(void){
    	GET_CURRENT_CHAR_WEAPON(GetPlayerPed(), &wWeapon);
    	if((wWeapon == WEAPON_PISTOL) && (IS_CHAR_SHOOTING(pPlayer))){
    		
    		REQUEST_MODEL(MODEL_dildo);
    		while(!HAS_MODEL_LOADED(MODEL_dildo)){
    			WAIT(0);
    		}
    		
    		CREATE_OBJECT(MODEL_dildo, prjX, prjY, prjZ, &ObjectProjectile, 1);
    		MARK_MODEL_AS_NO_LONGER_NEEDED(MODEL_dildo);
    		if(DOES_OBJECT_EXIST(ObjectProjectile)){
    			//SET_OBJECT_VISIBLE(ObjectProjectile, 0);
    			SET_OBJECT_AS_STEALABLE(ObjectProjectile, 1);
    			SET_OBJECT_ROTATION(ObjectProjectile, objrotX, 0.0, objrotZ);
    			SET_OBJECT_RECORDS_COLLISIONS(ObjectProjectile, true);
    			//SET_OBJECT_DYNAMIC(ObjectProjectile, 1);
    			APPLY_FORCE_TO_OBJECT(ObjectProjectile, 1, 0.0, 90.0, 0.0, 0.0, 0.0, 0.0, 1, 1, 1, 1);
    			WAIT(100);
    		}
    		if (HAS_OBJECT_COLLIDED_WITH_ANYTHING(ObjectProjectile)){
    			GET_OBJECT_COORDINATES(ObjectProjectile, &x,&y,&z);
    			ADD_EXPLOSION(x,y,z,EXPLOSION_CAR,10.0f,true,false,0.7f);
    			DELETE_OBJECT(&ObjectProjectile);
    		}
    	}
    }
    
    void dildo_aim(void){
    		GET_CURRENT_CHAR_WEAPON(GetPlayerPed(), &wWeapon);
    		if((wWeapon == WEAPON_DEAGLE) && (IS_BUTTON_PRESSED(0,BUTTON_L))){
    		
    			GET_GAME_CAM(&game_cam);
    			if (IS_CAM_ACTIVE(game_cam)){
    				GET_CAM_ROT(game_cam, &gcrotX, &gcrotY, &gcrotZ);// used for setting the object rotation and for some weird trig stuff below
    				GET_CAM_POS(game_cam, &gcX, &gcY, &gcZ);// used for the spawn point of the object, because the player is offset while aiming
    				if (gcrotX < 0.0)// the range for cam rot is -180 to 180, to set object rot we need 0 to 360
    				{
    					objrotX = gcrotX + 360.0;
    				}
    				else
    				{
    					objrotX = gcrotX;
    				}
    				if (gcrotZ < 0.0)
    				{
    					objrotZ = gcrotZ + 360.0;
    				}
    				else
    				{
    					objrotZ = gcrotZ;
    				}
    				/*  the trig stuff below could possibly be replaced with vectors, I have no idea how to do that though.  *
    				*   I apologize if this is confusing, but if you want to change the distance from the game_cam that the  *
    				*   object is spawned, adjust "3.0" to your preference on the first and fourth lines.  Also prjT is the  *
    				*   adjacent side from the pitch calculation, its purpose is to be the tangent in the following 2 lines */
    				prjT = (3.0 * COS(gcrotX));       // adj side calculation to be used as a tangent below
    				prjX = gcX - (prjT * SIN(gcrotZ));// calculates how far to spawn the object from the game_cam on the X plane
    				prjY = gcY + (prjT * COS(gcrotZ));// calculates how far to spawn the object from the game_cam on the Y plane
    				prjZ = gcZ + (3.0 * SIN(gcrotX)); // calculates how far to spawn the object from the game_cam on the Z plane
    			}
    		}
    }
    
    void dildo_shoot(void){
    	GET_CURRENT_CHAR_WEAPON(GetPlayerPed(), &wWeapon);
    	if((wWeapon == WEAPON_DEAGLE) && (IS_CHAR_SHOOTING(pPlayer))){
    		
    		REQUEST_MODEL(MODEL_dildo);
    		while(!HAS_MODEL_LOADED(MODEL_dildo)){
    			WAIT(0);
    		}
    		
    		CREATE_OBJECT(MODEL_dildo, prjX, prjY, prjZ, &ObjectProjectile, 1);
    		MARK_MODEL_AS_NO_LONGER_NEEDED(MODEL_dildo);
    		if(DOES_OBJECT_EXIST(ObjectProjectile)){
    			SET_OBJECT_AS_STEALABLE(ObjectProjectile, 1);
    			SET_OBJECT_ROTATION(ObjectProjectile, objrotX, 0.0, objrotZ);
    			SET_OBJECT_RECORDS_COLLISIONS(ObjectProjectile, true);
    			SET_OBJECT_DYNAMIC(ObjectProjectile, 1);
    			APPLY_FORCE_TO_OBJECT(ObjectProjectile, 1, 0.0, 90.0, 0.0, 0.0, 0.0, 0.0, 1, 1, 1, 1);
    			WAIT(100);
    		}
    		if (HAS_OBJECT_COLLIDED_WITH_ANYTHING(ObjectProjectile)){
    			//GET_OBJECT_COORDINATES(ObjectProjectile, &expx,&expy,&expz);
    			WAIT(500);
    			if(DOES_OBJECT_EXIST(ObjectProjectile)){
    				DELETE_OBJECT(&ObjectProjectile);
    			}
    		}
    	}
    }
    Mainly the part I'm concerned about is the rocket_shoot void.
    Add me on XBL = UtomAfryus69
    Add me on Skype = Xmcwildchild22


    My Xmc Modmenu - Online Player menu, bad stuff, weapon mods, and AIO features
    Reply With Quote  

  2. #2  
    jumper's Avatar
    jumper is offline Developer
    Join Date
    Jul 2005
    Posts
    288
    Downloads
    3
    Uploads
    0
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    Likes Given
    74
    Likes Received
    207
    You probably want to uncomment SET_OBJECT_DYNAMIC, most of the problems I had were related to that and how I used it.
    Emmanuel U likes this.
    Reply With Quote  

  3. #3  
    Emmanuel U's Avatar
    Emmanuel U is offline Developer
    Join Date
    Oct 2012
    Posts
    76
    Downloads
    0
    Uploads
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Likes Given
    89
    Likes Received
    65
    alright I tried, same problem.....was there any other things you had to add or take out? Also I was told SET_OBJECT_INITIAL_VELOCITY was better then applying force
    Add me on XBL = UtomAfryus69
    Add me on Skype = Xmcwildchild22


    My Xmc Modmenu - Online Player menu, bad stuff, weapon mods, and AIO features
    Reply With Quote  

  4. #4  
    jumper's Avatar
    jumper is offline Developer
    Join Date
    Jul 2005
    Posts
    288
    Downloads
    3
    Uploads
    0
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    Likes Given
    74
    Likes Received
    207
    Hard to say, it was a real pain to get it working with different models. Something as simple as a wait before applying force might work, but what works for that model, might not work right with others. I also never tried the record collisions thing, so I don't know how that affects launching it. This is how I did it in the first script:
    Code:
    {
    		ShootObject = 0;
    		while(!HAS_MODEL_LOADED(ProjectileModel[SelectedProjectile]))
    		{
    			WAIT(0);
    		}
    		CREATE_OBJECT(ProjectileModel[SelectedProjectile], prjX, prjY, prjZ, &ObjectProjectile, 1);
    		SET_OBJECT_VISIBLE(ObjectProjectile, 0);
    		MARK_MODEL_AS_NO_LONGER_NEEDED(ProjectileModel[SelectedProjectile]);
    		if(DOES_OBJECT_EXIST(ObjectProjectile))
    		{
    			WAIT(100);
    			SET_OBJECT_AS_STEALABLE(ObjectProjectile, 1);
    			SET_OBJECT_ROTATION(ObjectProjectile, objrotX, 0.0, objrotZ);
    			SET_OBJECT_DYNAMIC(ObjectProjectile, 1);
    			APPLY_FORCE_TO_OBJECT(ObjectProjectile, 1, 0.0, 90.0, 0.0, 0.0, 0.0, 0.0, 1, 1, 1, 1);
    			SET_OBJECT_VISIBLE(ObjectProjectile, 1);
    		}
    	}
    And this is from the latest version:
    Code:
    void ShootObject(void)
    {
    	GET_OBJECT_COORDINATES(objl_muz, &muzX, &muzY, &muzZ);
    	REQUEST_MODEL(objl_model);
    	while(!HAS_MODEL_LOADED(objl_model))	{	WAIT(0);	}
    	CREATE_OBJECT(objl_model, muzX, muzY, muzZ, &objl_object, 1);
    	while(!DOES_OBJECT_EXIST(objl_object))	{	WAIT(0);	}
    	SET_OBJECT_ROTATION(objl_object, olP - 20.0f, 0.0f, olH);
    	while(IS_OBJECT_STATIC(objl_object))
    	{
    		WAIT(0);
    		SET_OBJECT_DYNAMIC(objl_object, 1);
    		if(IS_BUTTON_PRESSED(0, BUTTON_O))
    		{
    			break;
    		}
    	}
    	APPLY_FORCE_TO_OBJECT(objl_object, 1, 0.0f, TO_FLOAT(objl_force) * 10, 0.0f, 0.0f, 0.0f, 0.0f, 1, 1, 1, 1);
    	MARK_OBJECT_AS_NO_LONGER_NEEDED(&objl_object);
    }
    Reply With Quote  

  5. #5  
    MaxSpeed's Avatar
    MaxSpeed is offline Member
    Join Date
    Jun 2012
    Location
    MI, USA
    Posts
    57
    Downloads
    0
    Uploads
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Likes Given
    29
    Likes Received
    18
    Use SET_OBJECT_INITIAL_VELOCITY. Look through my "weapon mods" source. It's a pretty ugly/confusing piece of coding, but that's how its done.
    Se7enSins: Muskelprotze
    Current Project: Stash v2 (Using MenuLib)
    Reply With Quote  

  6. #6  
    Emmanuel U's Avatar
    Emmanuel U is offline Developer
    Join Date
    Oct 2012
    Posts
    76
    Downloads
    0
    Uploads
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Likes Given
    89
    Likes Received
    65
    Can I haz an example? I was looking in your source but I couldn't really understand all the equations you used to set the velocity lol.
    Add me on XBL = UtomAfryus69
    Add me on Skype = Xmcwildchild22


    My Xmc Modmenu - Online Player menu, bad stuff, weapon mods, and AIO features
    Reply With Quote  

  7. #7  
    MaxSpeed's Avatar
    MaxSpeed is offline Member
    Join Date
    Jun 2012
    Location
    MI, USA
    Posts
    57
    Downloads
    0
    Uploads
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Likes Given
    29
    Likes Received
    18
    Well I'm going to have to go off the top of my head. Heres the basics:
    Code:
    Vector3 oVel;
    Vector3 oStart; //Fill with coords of where your spawning the object from
    Vector3 oTarget; //where you want the object to hit
    
    float fDist = 0.0f; //Distance between start and target
    And heres the basics of the get velocity:
    Code:
    #define SPEED 200
    
    GET_DISTANCE_IN_3D_WORLD(oStart.x,oStart.y,oStart.z,oTarget.x,oTarget.y,oTarget.z,&fDist);
    //Native is probably wrong but its something like this
    
    //A thanks to zorg93 who taught me this algorithm :D
    oVel.x = SPEED * (oStart.x - oTarget.x) / fDist;
    oVel.y = SPEED * (oStart.y - oTarget.y) / fDist;
    oVel.z = SPEED * (oStart.z - oTarget.z) / fDist;
    
    //spawn object & set dynamic
    
    SET_OBJECT_INITIAL_VELOCITY(oProjectile,oVel.x,oVel.y,oVel.z);
    You'll then need to detect when it hits something so you can delete it. I also suggest you have an object array of at least 10 so you're always able to shoot.
    Se7enSins: Muskelprotze
    Current Project: Stash v2 (Using MenuLib)
    Reply With Quote  

  8. #8  
    Emmanuel U's Avatar
    Emmanuel U is offline Developer
    Join Date
    Oct 2012
    Posts
    76
    Downloads
    0
    Uploads
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Likes Given
    89
    Likes Received
    65
    ok thanks, I noticed you are using SPEED defined to 200 but as in your weapon_mods.cpp on pastebin sets it to 500. Which one should I use?
    Add me on XBL = UtomAfryus69
    Add me on Skype = Xmcwildchild22


    My Xmc Modmenu - Online Player menu, bad stuff, weapon mods, and AIO features
    Reply With Quote  

  9. #9  
    MaxSpeed's Avatar
    MaxSpeed is offline Member
    Join Date
    Jun 2012
    Location
    MI, USA
    Posts
    57
    Downloads
    0
    Uploads
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Likes Given
    29
    Likes Received
    18
    500. I couldn't remember what it was.
    Se7enSins: Muskelprotze
    Current Project: Stash v2 (Using MenuLib)
    Reply With Quote  

  10. #10  
    Emmanuel U's Avatar
    Emmanuel U is offline Developer
    Join Date
    Oct 2012
    Posts
    76
    Downloads
    0
    Uploads
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Likes Given
    89
    Likes Received
    65
    ok it seemed to work, but is there any way to make it slow down when shooting it....it seems to shoot to fast that you can barely see it
    Add me on XBL = UtomAfryus69
    Add me on Skype = Xmcwildchild22


    My Xmc Modmenu - Online Player menu, bad stuff, weapon mods, and AIO features
    Reply With Quote  

Page 1 of 2 1 2 LastLast
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •