#Stuff not moving(properly)

1 messages · Page 1 of 1 (latest)

queen veldt
#

can you send picture of your script?

rotund dragon
#

k

queen veldt
#

where you declare hitPoint

rotund dragon
#
 if (Input.GetMouseButtonDown(1))
            if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity, layerMask))
            {
                Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);
                Debug.Log("Did Hit");
                hitPoint = hit.point;
                Debug.Log(hitPoint);
                Vector3.MoveTowards(player.transform.position = Vector3.MoveTowards(player, hitPoint, step));


            }
            else
            {
                Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * 1000, Color.white);
                Debug.Log("Did not Hit");
            }```
queen veldt
#

thx

rotund dragon
#

wait

queen veldt
#

Vector3.MoveTowards(player.transform.position = Vector3.MoveTowards(player, hitPoint, step));

rotund dragon
#

that doesnt look right

queen veldt
#

this line seems weird

rotund dragon
queen veldt
#

Vector3.MoveTowards(

#

you have to get rid of that

#

also you're only calling that line IF the player clicked mouse button AND if the raycast hit

rotund dragon
#

yes

#

Vector3.MoveTowards(player.transform.position = player, hitPoint, step);

#

is that right?

queen veldt
#

so you have to put that line outside of the if statements into something like Update or FixedUpdate

rotund dragon
#

ok

#

wait

queen veldt
rotund dragon
#

what do i have to do?

queen veldt
#

so change that weird line into

rotund dragon
#

yeah i did

#

should i try it?

queen veldt
#

and then move that line after the if/else statement

rotund dragon
#

ok

#

not moving

queen veldt
#

can you send your update/fixedupdate functions?

rotund dragon
#

ok

queen veldt
#

with line numbers, so it's easier to talk

rotund dragon
queen veldt
#

wait you already have it kinda written

rotund dragon
#

?

queen veldt
#

so put player.transform.position = Vector3.MoveTowards(player.transform.position, hitPoint, step)); this line right after line 19

#

so on line 20

rotund dragon
#

ok

#

in that else category?

queen veldt
#

yes

rotund dragon
#

ok

#

but thats not part of the code i'm working on

#

23 - 40 is the code i'm using

queen veldt
#

ik but when you use the grapple hook, grappling.IsGrappling() return true, right?

rotund dragon
#

that's part of the other grappling hook

rotund dragon
#

that's a different function though

queen veldt
#

the Vector3.movetowards() will only call ONCE, when the player clicks the button

#

which will only move the player a fraction of a unit

rotund dragon
#

but thats a different function

#

line 23- 40 is the function i'm working on

queen veldt
#

So instead, we want to move the player towards the point of grapple, EVERY FRAME that the player uses the grappling hook

rotund dragon
#

yes

#

but

#

ohhh lemme try something

#

so this is the code i am using:

queen veldt
#

Ye I also had that weird problem

#

try it without code tags

rotund dragon
queen veldt
#

ok

rotund dragon
#

that is the code for what i'm doing

queen veldt
#

why are lines 33&34 the same?

rotund dragon
#

i'm not sure

queen veldt
#

but line 33 will only get called once

#

which kinda doesn't work

rotund dragon
#

well i guess if it moves to the location until you stop holding rmb, then it will be fine

queen veldt
#

yes

#

that's what it does rn (I think)

rotund dragon
#

it only does it once though

queen veldt
#

Instead of Input.GetMouseButtonDown use Input.GetMouseButton(1)

rotund dragon
#

ahhhh

#

well it's working now

#

i just need to crank up the speed

#

thanks for the help

#

should work now

#

wait

#

it's not moving right

#

it's moving the wrong direction

#

well that feature isn't really needed, i'll just note it out and leave it for now