Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
Sign in to follow this  
Aeleas

Use raycast as a pointer ?

Question

I'm using third person camera for a car. this car have  a gun. it shooting but because the camera is above the car it get hard the aim at any enemy or spot far from the car. I need from my raycast give me the coordination (X,Y) of any object block the ray, so that can i use it for my bullet direction.

here is my code:

Please login or register to see this code.

What ever in the middle of my screen my bullet can reach it.

I don't know if this is right or wrong but i have to try.

maxresdefault.jpg

 

Share this post


Link to post
Share on other sites

11 answers to this question

Recommended Posts

  • 0

what is your problem exactly? this should work

 

just do If(hit.collider){ blah blah } 

Share this post


Link to post
Share on other sites

  • 0

My point is how to make my bullets go to any spot my raycast touch it.  Now my car gun move with the camera direction. if i shoot. the bullet go under or above the of the target. Even if this target is in the middle of my screen.  I don't know if what i'm doing is right or wrong. What i do is to make the raycast give me the distance (X,Y) of any object hit the ray, and then transfer these values to car gun. the spot that ray hit it, the gun or bullet will pointed at it, so when I fire my bullet will hit it, no matter how fat its. is this right or wrong ?

 

OK. here is my code with the bullet. I need bullet move to the spot that raycast hit it. 

Please login or register to see this code.

 

 

Share this post


Link to post
Share on other sites
  • 0

You want to add force to the bullet towards the ray cast hit position (position - otherPosition) rather than than simply shooting straight forward like your doing now. 

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

Thanks man. yes it run but still needs work.

I make a small prototype game to test everything. But still i don't know why it not shoot the spot that camera raycast hit it ? is there anything wrong i make ?

image.png

Here is the new script

Please login or register to see this code.

 

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

No. Nothing there.

I will think in something different.

Share this post


Link to post
Share on other sites
  • 0

Very simple

Just clamp your camera viewangles for something realistic

For tank cannon you need to calculate angle from tank cannon to raycast hit point then you would rotate tank cannon with calculated angles

 

Bullet seems too slow, either add prediction like in real life or make it travel faster like it should from that distance

Edited by nub

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

Yesterday i found this tutorial. It have my idea. I will try to fix my code now to match the same result in the tutorial.

Please login or register to see this link.

Share this post


Link to post
Share on other sites
  • 0

Your right. Thank you. :)

I still fighting with this stupid script. I work with first person camera not with the third.

God help me.

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...