has anyone tried to make a character that already moves?
by user 191204280198234122
has anyone tried to make a character that already moves?
by user 191204280198234122
and i can see this error every minut
by user 191204280198234122
Youhoo update
by user 191204280198234122
with this if i type āsā (for down) my camera move (but for now iām going to void lol)
by user 191204280198234122
getWorldPosition & setWorldPosition work ?
by user 191204280198234122
yes
incredible i have done !
by user 191204280198234122
You now how can i set a system like frames per second, because if i type s, he record 1500 entry
by user 191204280198234122
Yes, you can use this.context.time.deltaTime
ty
by user 191204280198234122
Done! I can move in map properly
by user 191204280198234122
Nice well done
Have any function for get mouseposition like event listener ?
by user 191204280198234122
(not for click, for follow all time)
by user 191204280198234122
import { Behaviour, serializeable } from "@needle-tools/engine";
import { setWorldPosition } from "@needle-tools/engine/engine/engine_three_utils";
import { getWorldPosition } from "@needle-tools/engine/engine/engine_three_utils";
import { Object3D, Vector3 } from "three";
export class PlayerControl extends Behaviour {
@serializeable()
public speed: number = 1;
public update() {
const time = this.context.time.deltaTime / 100;
const walk = this.speed * time;
window.onmousemove = (e) => {
const x = e.movementX;
this.gameObject.rotation.y += x * 0.002;
}
document.addEventListener("keydown", (event) => {
const key = event.key;
const position = getWorldPosition(this.gameObject);
if (key === "w") {
position.z -= walk;
} else if (key === "s") {
position.z += walk;
} else if (key === "a") {
position.x -= walk;
} else if (key === "d") {
position.x += walk;
}
setWorldPosition(this.gameObject, position);
}, false);
}
}
export default PlayerControl;
by user 191204280198234122
I share my finally code for today, with this script you can move on right, left, up and down.
You can also turn camera on right or left
by user 191204280198234122
I worked on the same problem and created a different solution :
import { AssetReference, Behaviour, Camera, serializeable } from "@needle-tools/engine";
import { Transform } from "@needle-tools/engine/engine-schemes/transform";
import { Mathf } from "@needle-tools/engine/engine/engine_math";
import { getWorldPosition, setWorldPosition } from "@needle-tools/engine/engine/engine_three_utils";
import { Quaternion, Vector3 } from "three";
export class PlayerMovement extends Behaviour {
private xRotation: number = 0;
private _currentSpeed: Vector3 = new Vector3(0,0,0);
private _temp: Vector3 = new Vector3(0,0,0);
@serializeable(Camera)
public camera: Camera = new Camera;
@serializeable()
public speed: number = 1;
public update(){
const forward = this.context.input.isKeyPressed("w");
const backward = this.context.input.isKeyPressed("s");
const left = this.context.input.isKeyPressed("a");
const right = this.context.input.isKeyPressed("d");
const stepForward = forward ? 1 : 0 + backward ? -1 : 0;
const stepRight = right ? -1 : 0 + left ? 1 : 0;
this._currentSpeed.z += stepForward * this.speed * this.context.time.deltaTime;
this._currentSpeed.x += stepRight * this.speed * this.context.time.deltaTime;
this._temp.copy(this._currentSpeed);
this._temp.applyQuaternion(this.gameObject.quaternion);
this.gameObject.position.add(this._temp);
this._currentSpeed.multiplyScalar(1 - this.context.time.deltaTime * 10);
window.onmousemove = (e) => {
const x = e.movementX;
this.gameObject.rotation.y += x * 0.002;
const y = e.movementY;
this.xRotation -= y;
this.xRotation = Mathf.clamp(this.xRotation, -90, 90);
this.camera.gameObject.quaternion.z = this.xRotation * -0.002;
}
}
}
export default PlayerMovement;
by user 377826570385227778
Hope it can help the next person looking at this topic!
by user 377826570385227778