Skip to content

So i am new to game development speceficly 3d games and i wonder why this code for the character to move isnt working any ideas or better code would be appreciated

Not downloaded yet
2 points25 comments
Open on Reddit
About this post
Posted
Archived
Score
2 · 58% up
Kind
Image
ID
rr67pm

Author

3
posts
8
comments
2
media
View profile

25 comments

The V in vertical needs to be capitalised.

Input.GetAxis(“Vertical”);

Also make sure you’ve attached the script to an object, like the player, or it won’t work.

10 points

To get an obvious question out of the way: did you attach the script to the object.

It must be attatched to something for it to even start.

4 points

I mean i am stupid just not that stupid

-12 points

Nobody assumes you are stupid. Just that you are uninformed. Which is nothing to be ashamed of.

Just writing scripts and assuming they will do stuff on their own is not a completely absurd assumption to make. Especially considering that this is exactly how Systems work in the new DOTS stack (no, don't look that up yet).

9 points

Alright. Now let's talk about the transform. I would try typing 'this' which targets the script. Also doing 'this.gameObject' targets the object that the script is attached to. So it would be something like:

this.gameObject.transform.position

-3 points

Remove the faulty semi colon on your last line. Also currently your speed value of 0.1 f means that per update you move that amount.

You should add a „ * Time.DeltaTime „ and normalize your moveDirection as currently you d move faster diagonally. (The magnitude of your vector would be higher then 1)

Also make sure that your monobehaviour is attached to your game object.

Additionally, you could cache your transform on top of your class but I think you don’t have to do that anymore as unity does it somewhat automatically for performance increase. (Isn’t extremely significant for one instance.

Also, write your Script names with uppercase letters. ( just a Convention, not Beck Breaking if you don’t)

Ex. Move PlayerManager GameManager ObjectMovesCircular

3 points

Yeah, collective of what everyone else said: -Get rid of that extra semicolon at transform.position += moveDirection*speed;

-Capitalize the word "Vertical" or it won't take that directional input at all

I'm not too sure on what next without seeing it, but those 2 are the biggest points to correct.

Let us know!

2 points

I'm not too familiar with the environment, but is that a rogue semi colon on the last line of before the "*"?

1 points

You are right it was an error but the model still wont move for some reason

1 points

I think you also need to normalise your move direction vector, but that wouldn't explain why there's no movement at all.

Sorry, I dont know Unity so don't think I can be of much more help.

1 points

Looks like it, and that also would show an error with exactly what the problem is..

1 points

If I'm seeing the red error message at the borrom left of your screen right, I'm guessing it's not compiling.

1 points

Yea another guy saw the problem, but the real problem is that the model isnt moving

-1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.