I have a 3rd person mover script on a character. using the WSAD controls I move the character around. The camera is always behind the character.
I am trying to throw a projectile(rigidbody) from the characters’ position, to the position of my mouse (X&Y) with a force applied to the Z (forward) based on a power meter which is already scripted.
Please help
thanks in advance everyone! Having a great time learning!
have you tried to do this and run into problems or asking us how to do it?
I’m not sure how to convert/translate that data, a step in the right direction or some stub code would be very helpful!
What I did was grab the rocket script from the FPS Tutorial and then mounted the script to game object under the main camera. This allows me to rotate me camera in any direction (currently working out a bug in my X-rotation clamping), and then shoot in the direction that the camera is facing.
The rocketlanucher script doesn’t have any Y force added to it however, it just has a Z for forward motion. I want this to be a sort of angular lob you know? Perhaps using Lerp to go from one y position to the next y position without overshooting the destination y position.
More of like frisbee dynamics if you will? So hard to explain lol…
Okay so I did some more thinking…
I basically want to set the velocity of a rigidbody
to throw it into the air toward an object at the Y point of my mouse.
So, if you have enough power you will hit the object your mouse is on.
I have a rigidbody with the gravity turned off that I pick up and throw with this script:
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var power : Vector3 = Vector3(0,0,throwPower);
var theDirection : Vector3 = ray.direction;
var theDistance : Vector3 = power + theDirection;
objectThatIsGrabable.rigidbody.velocity = transform.TransformDirection(theDistance);
Is this even close? haha… if I’m not making any sense please someone tell me lol…
If you’re planning to make it act like a throw, wouldn’t it just continue upwards and not come down due to the rigidbody not having gravity?
I do see where you’re getting your idea, but again the rocketlauncher script is easier to use. All you have to do is add a Y force:
All you need to do is add gravity to your tossed object and you’re already done. I mean it’s much simpler than how you’re trying to tackle it. (With the only tough part being the coordination of how much power that it’s tossed at)
Want a 30 degree angle? Make the Y vector for the code above a fraction of the initial speed (such as… 2/3s)
I just feel that you’re trying to create something that’s already been done for you.
right but i want it to rise and then stay at a certain height (mouseY on screen) until it hits something