#Projectiles Not Following Cursors
1 messages · Page 1 of 1 (latest)
as u can see it works just fine when im shooting upwards
but when i shoot downwards it doesnt wok
it also slightly pushed me a bit when i shoot downwars
<@&823670121133768714>
what do you want us to do just guess? Provide the code
to make an object disappear is very simple I will link the documentation
use this if the projectile does not have a trigger collider
you can use this to destroy it
i recorded it
wait
lemme screenshot the code?
<@&823670121133768714>
I don't know what the raycast is being used for, but to follow the cursor the forceDirection should be assigned to cam.transform.forward. It seems like you reassign the forceDirection variable to a different Vector3 in your raycast. Let me know if that helps.
i see
i followed a tutorial
and it seems that the tutorial said the raycast is so that the projectile is being thrown in the middle
so how do i fix this?
This may not work, but what if you remove the Raycast and set Vector3 forceToAdd = forceDirection * throwForce;
can you give the link of the tutorial?
also in the raycast, isn't cam.position wrong? as in shouldn't it be cam.transform.position?
also shouldn't it be cam.transform.forward instead of cam.forward?
wait
THROWING Grenades, Knives and Other Objects - Unity Tutorial
I'm finally back with another tutorial, this time about Throwing grenades, knives, or literally anything you want in Unity 3D.
If the video has helped you in any way, make sure to leave a like!
Also subscribe for new helpful tutorials every week.
Links:
➤ DOWNLOAD the SCRIPT: https:...
thanks, aren't you getting any error for writing cam.position or cam.forward?
it should give an error imo
idk it didnt lol
aight
i found this comment in the video you sent
For anyone in 2022 and beyond struggling to get your projectile to throw STRAIGHT follow these steps:
*Above "GameObject projectile = Instantiate"
put: "Quaternion q = Quaternion.FromToRotation(Vector3.up, transform.forward);
objectToThrow.transform.rotation = q * attackPoint.transform.rotation;"
and then in "GameObject projectile = Instantiate(objectToThrow, attackPoint.position, objecTothrow.rotation);" change "objectTothrow.rotation" to ---> "q" or the name of the quaternion that you made in the line before.*
You're ensuring the projectile has the same rotation as your attack point. In the editor, ensure your attack point represents the angle at which you want your 3D object to shoot with. Also ensure to move your attack position to where you want your clone to spawn.
[]ioc
An image of your code is not helpful
When asking a question about a problem with code, people who are volunteering to help need the text of the code. Unless you are asking about your IDE - and not the code itself - images of the code are not an acceptable substitute.
Source: https://idownvotedbecau.se/imageofcode
Please send your code as a codeblock. If you don't know how to send a codeblock, type []cb
That is the most complicated way of achieving this that I've ever seen.
If the goal is for the orefab instance to have the same rotation as the attackPoint, simply input attackPoint.rotation as 3rd parameter of Instantiate.
No need for convoluted solutions like using FromToRotation.
aight guys the attackpoint has been fixed however it still slightly moved my character forward when i shoot any idea why?
Probably because your projectile collides with the character when it spawn, and they push each other away.
A solution to this would be to put the projectile on a layer that cannot collide with that of the player.
I agree its a complicated way of achieving this. Its from a youtube comment from the video hafizh linked, I thought it would be helpful.
Your solution is definitely less complicated and more useful.
?
What Zenvin is trying to say is that the collider on the projectile is colliding with the collider on the player, which causes the player to move back due to the collision. Colliders on the same layer will collide with each other (as per default settings).
You don't want the collider on the projectile to collide with the collider on the player. Therefore, you will need to make seperate layers for the projectile and the player.
fix what?
let me watch the video
what i showed at the last is the original prefab
do you want the penguin to not move at all?
no i coded a script where it should follow me and stop to shoot
but right now its following me but gets pulled by the snowball prefab and just stuck
the penguin is shooting the snowball, right?
its the same solution here
you will need to put the penguin and the snowball on seperate layers
yes
so that their colliders dont interact with each other
yes
also you can go to project settings
and set which layers should interact with each other
no problem
also
use Zenvin's solution for your original problem
not the one I gave you
alright
btw i made a script for a moving platform that make the player a child when collision
but even after i got off the moving platform its still making my player a child
im so sorry for asking too many questions im a newbie
i think it would be better to ask one question in one post
but to answer your question
you need to use the OnCollisionExit function