#Elucript - Trying to dash without flipping players Scale

1 messages ยท Page 1 of 1 (latest)

obtuse skiff
#
    private IEnumerator Dash()
    {
        source.PlayOneShot(dash);
        isDashing = true;
        canDash = false;
        float originalGravity = rb.gravityScale;
        rb.gravityScale = 0f;
        rb.velocity = new Vector2(transform.localScale.x * dashingPower, 0f);
        tr.emitting = true;
        yield return new WaitForSeconds(dashingTime);
        tr.emitting = false;
        rb.gravityScale = originalGravity;
        isDashing = false;
        yield return new WaitForSeconds(dashingCooldown);
        canDash = true;
    }

My current dash script just wait before responding because I will send some screen shots of other data aswell

#

I have an object called feet that determines if the player is grounded

#

Gun facing mouse (not flipped)

shadow star
#

alr

obtuse skiff
#

Gun facing away from mouse when flipped

shadow star
#

you have to rotate it 180

#

on Y axis

#

check if Mouse position is in the Negative of player's Xposition

#

if thats the case you rotate instead of flip

obtuse skiff
#

ok sorry if im making you repeat alot but we are talking about the gun or the player?

shadow star
#

flip will invert even the Pivot

shadow star
#

that's how it's done

#

if it's player/ gun w/e

#

if u just flip it , you will messup the pivot

#

so it will think UP is down

#

etc

#

not a good way to work with

#

so you just flip the Y and it should work accurately

obtuse skiff
#

ok so to also note I dont really need to flip the player because it rlly is not needed so is it possible I can just make my dash function not rely on the flip function?

shadow star
#

so his Red Arrow (forward direction in 2d)

#

is always infront

#

point away from him

#

so you can always dash forward

#

so you dont need to do extra checks

#

if player x > bla bla

obtuse skiff
#

so I need to rotate the player instead of flipping them

shadow star
#

and gun

obtuse skiff
#

how would I fix the players feet then

shadow star
#

it shouldnt be affect by rotation

#

it will stay at the bottom

obtuse skiff
#

I'm going to be honest with you I don't know half the stuff your saying not in a disrespectful way I'm just overthinking it a lot and trying to figure out how to even program it ๐Ÿ’€

I need to rotate the player on the y axis, then the gun, then make a transform (got no clue what that is) and it should display correctly? am I able to do this in just the player movement script?

shadow star
obtuse skiff
#

how to convert it into c# and reqrite my whole flip function

#

as of now

    private void Flip()
    {
        if (isFacingRight && mx < 0f || !isFacingRight && mx > 0f)
        {
            isFacingRight = !isFacingRight;
            Vector3 localScale = transform.localScale;
            localScale.x *= -1f;
            transform.localScale = localScale;
        }
#

I keep on trying to type in lua as the language

#

roblox is built different

shadow star
#

how are u getting isFacingRight through inputs ?

obtuse skiff
#
private bool isFacingRight = true;
shadow star
#

wait no thats bool

#

U dont need that

#

just mx

obtuse skiff
#

I got float mx

#

so just del bool ffacing right bool?

shadow star
#
if ( mx > 0f ){
//facing right.
 transform.rotation = Quaternion.Euler(0, 0, 0);}```
#
if ( mx < 0f ){
//facing left.
 transform.rotation = Quaternion.Euler(0, 180, 0);}```
#

here

obtuse skiff
#

ok so if mx is less then 0f
mx is the direction of the player?

shadow star
#

movementX ?

obtuse skiff
#

oh yeah that would make sense

shadow star
#

so you get the mouse axis

#

but only find the x

#

and do the same exact code

#

with the mouse X

obtuse skiff
#

I have a whole sep script for the shotgun

shadow star
#

how you flip player / shotgun is up to you if you're using mouse or movement

#

but they should match otherwise your player faces backwards if you move right while shooting left

#

so if u dash while shooting left it will dash right

obtuse skiff
#
if ( mx < 0f ){
//facing left.
 transform.rotation = Quaternion.Euler(0, 180, 0);}
else {
 transform.rotation = Quaternion.Euler(0, -180, 0);}

and that should fix my flip issue?

shadow star
#

write them like i sent them..

#

dont change thenm

#

y 0 is for normal direction (right)

#

180 is for left

obtuse skiff
#

would it help if I were to send my whole movement script?

obtuse skiff
#

alr thanks

shadow star
#
private void Flip()
    {
           if (mx > 0f)
        {
            //facing right.
            transform.rotation = Quaternion.Euler(0, 0, 0);
        }

        if (mx < 0f)
        {
            //facing left.
            transform.rotation = Quaternion.Euler(0, 180, 0);
        }
    }```
obtuse skiff
#

alright

#

so then I need to get the gun to flip

shadow star
#

also change ur dash direction

#

rb.velocity = new Vector2(transform.right * dashingPower, 0f);

obtuse skiff
#

alright

#

im taking it slow to try to understand how this fully work

obtuse skiff
#

however

#

its not to fond

shadow star
obtuse skiff
#

oh yeah

#

๐Ÿ’€

shadow star
#

oh wait

#

no

#

im tired lol hold on.

obtuse skiff
#

is it late for you?

shadow star
#

velocity = transform.right * dashpower

#

no vector

obtuse skiff
shadow star
#

but im just burnt out

obtuse skiff
#

pov life

#

no error

shadow star
#

XD

obtuse skiff
#

oh hey it works

#

the gun just needs to be flipped

#

can the gun be flipped in the player movement script?

#

I think I can just make a game object

#

public var

#

LOL

#

NOPE

shadow star
#

or mouse position

#

eg if its on the left of player

obtuse skiff
#

bro just gonna kill emself ๐Ÿ’€

shadow star
#

can you show the pivot of weapon too

obtuse skiff
#

yeah

#

I did transform.rotation = Quaternion.Euler(0, 0, 0);

shadow star
#

for shotgun imean

obtuse skiff
#

its just the center of the sprite I dont have an object made just for a pivot point

shadow star
#

no I mean in the scene pivot

obtuse skiff
#

for the whole game?

shadow star
shadow star
obtuse skiff
#

will this do?

shadow star
#

is that set to Local Space btw

obtuse skiff
#

yeah

#

its not

#

set to pivot

#

tho

shadow star
#

show pivot

#

after u set it

obtuse skiff
shadow star
#

for accurate flip

#

you have sprite editor

obtuse skiff
#

asprite

shadow star
#

you should be able to fix the pivot there

#

no i mean in unity

obtuse skiff
#

oh

#

uhh

#

is that a plug in

#

or built in

shadow star
shadow star
#

in the assets folder

obtuse skiff
#

done

#

or keep it center?

shadow star
obtuse skiff
shadow star
obtuse skiff
#

re apply the texture?

shadow star
#

save it

#

yea

#

now in the scene test it

#

see if it flips

#

correct

obtuse skiff
#

yes I just need to make its position more accurate

shadow star
obtuse skiff
#

shoot wait I did smth and it broke

shadow star
obtuse skiff
#

idk I refreshed

#

it just decided to be mouseaphobic

#

but its all go now

#

off pos tho

shadow star
#

also where is player pivot at center ?

obtuse skiff
#

yeah

shadow star
obtuse skiff
#

it doesnt rlly work as intended but ill figure the bullet part later

#

I think its the bullet code thats broken tho

#

but thats a future problem

shadow star
obtuse skiff
#

bullet but lets just focus on getting the gun to be in correct pos first

shadow star
obtuse skiff
#

pretty much the bullet shoots 90deg away from were you are pointing

shadow star
#

whats ur bulet direction, you should shoot the same exacct way on your bullet as dash

#

transform.right * speed, for direciton

#

just remember transform.right is always gonna be forward now

obtuse skiff
#

ok before we jump into bullet fix when rotating the guns pivot point changes

obtuse skiff
#

when the player flips

#

norm p point

#

oh ok so

shadow star
obtuse skiff
#

the sprite flips

#

I need it to not flip

#

the pivot point is the same

obtuse skiff
shadow star
obtuse skiff
#

WAIT LOL thats weird

#

the gun like

#

let me record

shadow star
#

unless u directly move child , its otherwise affected by parents transform

obtuse skiff
shadow star
#

best to not parent it and just make it follow player via script

obtuse skiff
#

ahh yeah

#

I need to get the players pos

#

and make it the guns pos

shadow star
#

yes

obtuse skiff
#

so I can make a public gameobject

#

and put player in it

shadow star
#

public Transform player

obtuse skiff
#

how so

shadow star
#

drag player in there

#

transform.position = player.position (inside update)

obtuse skiff
#

it still does it smth is up with the looking script then

#

is it fine if I give you nitro after this btw? you spent a good amount of time on me

shadow star
#

no worries

shadow star
obtuse skiff
#

ok so

#

It looks like to me

#

gun faces mouse right

#

it then adjusts

#

after it rotates

#

/flips

shadow star
obtuse skiff
#

wym

shadow star
obtuse skiff
#

transform.rotation = Quaternion.Euler(0, 180, 0);

obtuse skiff
#

player

#

I still have no clue why it does that

#

because its following player

shadow star
#

that should have no effect if its not parented to gun

obtuse skiff
#

alright so its view problems then

shadow star
obtuse skiff
#

yeah error

shadow star
#

oh wait

#

ur not using the main camera

obtuse skiff
#

would that be a game object?

shadow star
#

Camera.main.

#

u need that

#

as of now ur using the class

obtuse skiff
#

then the whole line breaks

shadow star
#

not the actuall main cam

obtuse skiff
shadow star
#

ScreenToWorldPoint

#

myb

obtuse skiff
#

now its happy

#

ok so

#

screentoworld

#

is pretty self explanatory

shadow star
#

yes, from screencamera to the world

obtuse skiff
#

what does the to ray

#

do

shadow star
#

ray will return a raycast

#

like a line that shoots from camera to wherever it points

obtuse skiff
#

sounds like ill need to use that later on in dev

shadow star
#

used for raycasting

obtuse skiff
#

used for guns majority of time

shadow star
#

yes raycasts are important but not rn

#

u already using kind of a raycast with gravity check

shadow star
#

even buttons in UI use raycasts

#

behind the scenes tho

obtuse skiff
#

damn thats

#

unexpected

#

also it broke more lol part of debugging

#

now the size scales

#

and it stays in place

#

OH WAIT

#

its rotating

#

like a 3d

#

object

shadow star
#

also is the camera set to Orthographic

#

just checking

obtuse skiff
#

yes

#

thats cool

#

most def use for later

shadow star
#

wth

obtuse skiff
#

upgraded from 2d to 3d

#

๐Ÿ’€

shadow star
#

something is up with that rotation..

obtuse skiff
#

the var

#

is doing 3d stuff

#

I set it to vector2 but just set us back to the og problem of moving up and down and not moving to player

shadow star
#

try ```cs
var mousePosition = Input.mousePosition;
mousePosition.z = 0;
var dir = Camera.main.WorldToScreenPoint(mousePosition);
transform.right = dir;

obtuse skiff
#

var

#

before mouse pos?

shadow star
obtuse skiff
#

k

shadow star
#

dir and mousePos

obtuse skiff
#

same error for both lines

#

that dont have

#

var

shadow star
obtuse skiff
shadow star
#

ur missing ; somewhere

shadow star
obtuse skiff
#

oh im just

#

stopid

#

ok

#

yeah I kinda fogor

#

to add a ;

shadow star
#

lol

obtuse skiff
#

man without you id be spending hours

#

looking at code

#

just to not

#

put the damn ;

shadow star
#

it happens to me too if it makes you feel any better lol

#

and i've been at it for years

obtuse skiff
#

dang

#

ok so

#

it doesnt flip

#

and is super slow

shadow star
#

does it rotate ok

#

follow mouse i mean

obtuse skiff
shadow star
obtuse skiff
#

zero

shadow star
obtuse skiff
shadow star
#

maybe try this script. see if itworks cs var mousePos = Input.mousePosition; mousePos.z = 0; Vector3 objectPos = Camera.main.WorldToScreenPoint (transform.position); mousePos.x = mousePos.x - objectPos.x; mousePos.y = mousePos.y - objectPos.y; float angle = Mathf.Atan2(mousePos.y, mousePos.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));

obtuse skiff
#

ok now its just missing the flip

#

and follow

shadow star
obtuse skiff
#

its set right to 0

shadow star
#

does it flip and follow mouse ?

obtuse skiff
#

it does not flip

#

the only thing changing is the v value

#

z

#

mb

shadow star
#

did u put 180 in the Y

obtuse skiff
#

this correct?

shadow star
obtuse skiff
#

yeah

shadow star
#

does gun flip ?

obtuse skiff
#

I did that

#

and no

#

it does not

shadow star
#

ok

#

i give u the timestap

#

on the flip part

obtuse skiff
#

yeah ill look into that but I need to sleep so I dont miss the bus it is almost 1am

#

im a man of my words and will give you nitro do you want it now or tmmr?

shadow star
obtuse skiff
#

alright

shadow star
#

Ill be around no worries

obtuse skiff
#

alr man

shadow star
#

link in my profile

obtuse skiff
#

alright ill give you a shout out on myn

#

or feature it

shadow star
#

thanks!

#

ttyl

obtuse skiff
#

cya

obtuse skiff
#

im back lets try to fix finish this

obtuse skiff
#

alright so after I watched his video I got the hang off it and it works
Issues left:
When the player "flips" the gun breaks
Bullet not working (for later)

#

Fixed the gun not following the player