Hey peeps. So, my game has come a long way. Made several new scripts for custom this and that:
Player movement:
1.Jesse Anders pointed me in the right direction for actually moving anything.
2.legend411 showed me to use forces, rather than actual movement. (much smoother thanks)
3.Vicenti who helped with everything related to looking.
Everything else I did. but as you can guess by this thread, im stuck on something.
so i have this tidbit of a problem. I decided to use the machinegun.js script from the fps tutorial, and it works great.
problem is, it aims at the middle of the screen. I need that thing to aim where the mouse is aiming.
I can see in the 3rd person shooter that the “player” aims where the mouse is aiming by creating an object that you cant see that moves with the mouse and changes how close it is by colliding with something, and aiming the players gun at that point.
that seems like 100% of what i need.
Ive deduced that the machinegun.js file (located here var range = 100.0;var fireRate = 0.005;var force = 10.0;var damage = 5.0;var - Pastebin.com)
has this function here that needs to be changed:
function FireOneShot () {
var direction = transform.TransformDirection(Vector3.forward);
var hit : RaycastHit;
// Did we hit anything?
if (Physics.Raycast (transform.position, direction, hit, range)) {
// Apply a force to the rigidbody we hit
if (hit.rigidbody)
hit.rigidbody.AddForceAtPosition(force * direction, hit.point);
// Place the particle system for spawing out of place where we hit the surface!
// And spawn a couple of particles
if (hitParticles) {
hitParticles.transform.position = hit.point;
hitParticles.transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
hitParticles.Emit();
}
// Send a damage message to the hit object
hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
}
Part of the aiming for the 3rd person is done (i think) with ShooterGameCamera.cs (which btw i dont know c#) (found here using UnityEngine;using System.Collections;// 3rd person game-like camera con - Pastebin.com)
and
With gunaimer.cs (here using UnityEngine;using System.Collections;public class GunAimer : ExecutionO - Pastebin.com) which depends on pivot which ill need, the target, which is that sphere that moves around and the gun, of course where the bullets n stuff are coming from.
i deleted all other scripts and only broke it when i started deleting parts of the human, not sure what its depending on. if i replace the human with a sphere when the game is running, it works, but when i turn it off, delete the human, and do everything i did to make it work with just a sphere, it dosent work. odd stuff.
so anyway, i could use some help with this. after i get this done, im pretty much done (besides graphics)
basically what needs to happen:
PlayerWeapons <— This needs to point to the mouse target
MachineGun <--- child of weapons, because there will be more weapons the parent needs to move. ``machineGun <--- this is the gun AnyOtherGun ← because of the addition of guns the parent needs to move
``anyotherGun <— blah.
(oh and i prefer java, but if youre writing the code and im just copy pasting it to see if it works, then by all means use whatever u like to code in)
edit: btw, those three names up top that helped me, you can bet they will be in the credits of the game. and if this game actually makes money on a regular basis, you can also bet ill be sharing that money with them.