#Projectiles Not Following Cursors

1 messages · Page 1 of 1 (latest)

slender tendon
#

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>

wraith dove
#

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

slender tendon
#

wait

#

lemme screenshot the code?

slender tendon
#

<@&823670121133768714>

hasty portal
#

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.

slender tendon
#

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?

hasty portal
#

This may not work, but what if you remove the Raycast and set Vector3 forceToAdd = forceDirection * throwForce;

slender tendon
#

aight ill try

#

thanks

slender tendon
#

aww man

#

it didnt work

hasty portal
#

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?

slender tendon
#

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:...

▶ Play video
hasty portal
#

thanks, aren't you getting any error for writing cam.position or cam.forward?

slender tendon
#

no

#

when i head back to unity it didnt say any error

hasty portal
#

it should give an error imo

slender tendon
#

idk it didnt lol

hasty portal
#

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.

slender tendon
#

yooo

#

thank you so much

magic egret
cedar bisonBOT
#

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

slender tendon
#

my bad

#

sorry im new to the development community

distant creek
slender tendon
#

aight guys the attackpoint has been fixed however it still slightly moved my character forward when i shoot any idea why?

distant creek
#

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.

slender tendon
#

oh wait

#

if i adjust the rigidbody collision settings it should work

hasty portal
hasty portal
hasty portal
#

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.

slender tendon
#

i see

#

btw do u have any idea how to fix this

hasty portal
#

fix what?

slender tendon
#

the enemy seems to get pulled by the original snowball prefab

hasty portal
#

let me watch the video

slender tendon
#

what i showed at the last is the original prefab

hasty portal
#

do you want the penguin to not move at all?

slender tendon
#

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

hasty portal
#

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

slender tendon
#

yes

hasty portal
#

so that their colliders dont interact with each other

slender tendon
#

wait lemme try

#

so i just make a new layer and change them right?

hasty portal
#

yes

#

also you can go to project settings

#

and set which layers should interact with each other

slender tendon
#

do i do that in the tags and layer?

#

oh i found it in physics

#

thanks bro

hasty portal
#

no problem

#

also

#

use Zenvin's solution for your original problem

#

not the one I gave you

slender tendon
#

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

hasty portal
#

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

slender tendon
#

alright ill try

#

do i just on the function or do i also need to write an if script

hasty portal
#

you need to write an if statement

#

in the OnCollisionExit function